Skip to content

Commit 05e8855

Browse files
authored
Rename reviewer role to review_aiod_resources, make alias configurable (#487)
2 parents 8b53954 + 29a89c7 commit 05e8855

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ KEYCLOAK_CLIENT_SECRET="QJiOGn09eCEfnqAmcPP2l4vMU8grlmVQ"
1717
REDIRECT_URIS=http://${HOSTNAME}/docs/oauth2-redirect
1818
POST_LOGOUT_REDIRECT_URIS=http://${HOSTNAME}/aiod-auth/realms/aiod/protocol/openid-connect/logout
1919
AIOD_KEYCLOAK_PORT=8080
20+
REVIEWER_ROLE_NAME=review_aiod_resources
2021

2122
EGICHECKINALIAS=
2223

data/keycloak/data/import/aiod-realm.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@
5353
"clientRole" : false,
5454
"containerId" : "3df7e07d-ebbd-41c4-bc0c-1ba0e1a40ac5",
5555
"attributes" : { }
56-
}, {
57-
"id" : "ae367056-af48-4b9b-bec9-bfc57f91d218",
58-
"name" : "reviewer",
59-
"description" : "Allows reviewing of metadata assets",
60-
"composite" : false,
61-
"clientRole" : false,
62-
"containerId" : "3df7e07d-ebbd-41c4-bc0c-1ba0e1a40ac5",
63-
"attributes" : { }
6456
}, {
6557
"id" : "427c7161-bcf0-4f2d-a6fd-291dbad3db1a",
6658
"name" : "default-roles-aiod",
@@ -91,6 +83,14 @@
9183
"clientRole" : false,
9284
"containerId" : "3df7e07d-ebbd-41c4-bc0c-1ba0e1a40ac5",
9385
"attributes" : { }
86+
}, {
87+
"id" : "2acb73ad-574d-4b77-b5dc-0fa9fd2ec8d7",
88+
"name" : "${REVIEWER_ROLE_NAME}",
89+
"description" : "Can review submitted AIoD resources",
90+
"composite" : false,
91+
"clientRole" : false,
92+
"containerId" : "3df7e07d-ebbd-41c4-bc0c-1ba0e1a40ac5",
93+
"attributes" : { }
9494
} ],
9595
"client" : {
9696
"realm-management" : [ {
@@ -1232,7 +1232,7 @@
12321232
"subType" : "authenticated",
12331233
"subComponents" : { },
12341234
"config" : {
1235-
"allowed-protocol-mapper-types" : [ "saml-user-property-mapper", "oidc-usermodel-attribute-mapper", "saml-user-attribute-mapper", "oidc-sha256-pairwise-sub-mapper", "oidc-full-name-mapper", "oidc-usermodel-property-mapper", "oidc-address-mapper", "saml-role-list-mapper" ]
1235+
"allowed-protocol-mapper-types" : [ "saml-role-list-mapper", "oidc-usermodel-property-mapper", "oidc-usermodel-attribute-mapper", "oidc-sha256-pairwise-sub-mapper", "oidc-full-name-mapper", "saml-user-property-mapper", "saml-user-attribute-mapper", "oidc-address-mapper" ]
12361236
}
12371237
}, {
12381238
"id" : "10f8b9b2-1038-4c98-b7a5-a9ac88fed69e",
@@ -1274,7 +1274,7 @@
12741274
"subType" : "anonymous",
12751275
"subComponents" : { },
12761276
"config" : {
1277-
"allowed-protocol-mapper-types" : [ "oidc-usermodel-property-mapper", "saml-user-property-mapper", "oidc-full-name-mapper", "oidc-sha256-pairwise-sub-mapper", "saml-user-attribute-mapper", "oidc-usermodel-attribute-mapper", "saml-role-list-mapper", "oidc-address-mapper" ]
1277+
"allowed-protocol-mapper-types" : [ "oidc-usermodel-property-mapper", "saml-user-property-mapper", "saml-user-attribute-mapper", "oidc-address-mapper", "oidc-usermodel-attribute-mapper", "oidc-full-name-mapper", "oidc-sha256-pairwise-sub-mapper", "saml-role-list-mapper" ]
12781278
}
12791279
}, {
12801280
"id" : "1d21f027-e0ae-4b80-b95e-f21d9426f115",

data/keycloak/data/import/aiod-users-0.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
} ],
1818
"disableableCredentialTypes" : [ ],
1919
"requiredActions" : [ ],
20-
"realmRoles" : [ "reviewer", "default-roles-aiod" ],
20+
"realmRoles" : [ "default-roles-aiod", "review_aiod_resources" ],
2121
"notBefore" : 0,
2222
"groups" : [ ]
2323
}, {
@@ -51,8 +51,8 @@
5151
"type" : "password",
5252
"userLabel" : "My password",
5353
"createdDate" : 1689685345632,
54-
"secretData" : "{\"value\":\"VB2FW3ylhoLKfwSDNKgg3UR0RVtEDdilsVNmcmN8uQc=\",\"salt\":\"T/PRFYHhKbI1wyKGcQFwOw==\",\"additionalParameters\":{}}",
55-
"credentialData" : "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\",\"additionalParameters\":{}}"
54+
"secretData" : "{\"value\":\"fT1UBmMhrRt/Z/0DL5YdyFM/9yAP5YyE4DQOhHsD8DyEp66qo+ZQ5tGiMhCeBMTVFHoG4wOP3LakEXOCvtBADA==\",\"salt\":\"FL4nLEZy2MRRMb5rH8ylHA==\",\"additionalParameters\":{}}",
55+
"credentialData" : "{\"hashIterations\":210000,\"algorithm\":\"pbkdf2-sha512\",\"additionalParameters\":{}}"
5656
} ],
5757
"disableableCredentialTypes" : [ ],
5858
"requiredActions" : [ ],

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
- ./src/config.override.toml:/app/config.override.toml:ro
1010
environment:
1111
- KEYCLOAK_CLIENT_SECRET=$KEYCLOAK_CLIENT_SECRET
12+
- REVIEWER_ROLE_NAME=$REVIEWER_ROLE_NAME
1213
- ES_USER=$ES_USER
1314
- ES_PASSWORD=$ES_PASSWORD
1415
ports:
@@ -149,6 +150,7 @@ services:
149150
environment:
150151
- REDIRECT_URIS=$REDIRECT_URIS
151152
- POST_LOGOUT_REDIRECT_URIS=$POST_LOGOUT_REDIRECT_URIS
153+
- REVIEWER_ROLE_NAME=$REVIEWER_ROLE_NAME
152154
ports:
153155
- ${AIOD_KEYCLOAK_PORT}:8080
154156
volumes:

src/authentication.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
realm_name=KEYCLOAK_CONFIG.get("realm"),
4444
verify=True,
4545
)
46+
_REVIEWER_ROLE = os.getenv("REVIEWER_ROLE_NAME")
4647

4748

4849
@dataclasses.dataclass
@@ -59,7 +60,8 @@ def has_any_role(self, *roles: str) -> bool:
5960

6061
@property
6162
def is_reviewer(self):
62-
return "reviewer" in self.roles
63+
assert _REVIEWER_ROLE is not None, "Must configure role `reviewer` in config.toml file." # noqa: S101
64+
return _REVIEWER_ROLE in self.roles
6365

6466

6567
async def _get_user(token) -> KeycloakUser:

src/routers/review_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ def _review_resource(
143143
if submission is None:
144144
raise HTTPException(
145145
status_code=status.HTTP_400_BAD_REQUEST,
146-
detail=f"No review with identifier {review.submission_identifier} found.",
146+
detail=f"No submission with identifier {review.submission_identifier} found.",
147147
)
148148
if not submission.is_pending:
149149
raise HTTPException(
150150
status_code=status.HTTP_400_BAD_REQUEST,
151-
detail="Review is no longer pending, no new decision may be made.",
151+
detail="Submission is no longer pending review, no new decision may be made.",
152152
)
153153
register_user(user, session)
154154

src/tests/authorization/test_authorization.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import contextlib
22
import json
3+
import os
34
from http import HTTPStatus
45
from unittest.mock import Mock
56

67
import pytest
8+
from dotenv import load_dotenv
79
from starlette.testclient import TestClient
810

911
from authentication import keycloak_openid, KeycloakUser
@@ -18,9 +20,13 @@
1820
from database.model.knowledge_asset.publication import Publication
1921
from routers.review_router import ListMode
2022

23+
load_dotenv()
24+
2125
ALICE = KeycloakUser("Alice", {"edit_aiod_resources"}, "alice-sub")
2226
BOB = KeycloakUser("Bob", {"edit_aiod_resources"}, "bob-sub")
23-
REVIEWER = KeycloakUser("Reviewer", {"reviewer", "edit_aiod_resources"}, "reviewer-sub")
27+
review_role = os.getenv("REVIEWER_ROLE_NAME")
28+
assert review_role, "The REVIEWER_ROLE_NAME environment variable must be set"
29+
REVIEWER = KeycloakUser("Reviewer", {review_role, "edit_aiod_resources"}, "reviewer-sub")
2430

2531

2632
def _register_user_in_db(user: KeycloakUser) -> KeycloakUser:

0 commit comments

Comments
 (0)