Skip to content

Commit

Permalink
Added: Central Keycloak configuration based on groups
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Nov 14, 2023
1 parent be6b6f6 commit 45ca734
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2023-10-23
## [1.0.0] - 2023-11-14
### Added
- Init project
- Prototype
Expand Down Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dockerignore
- Gitignore
- Default template variable for exporter and reporter
- Central Keycloak configuration based on groups

## Fixed
- Update teiler apps in sidebar
Expand Down
4 changes: 3 additions & 1 deletion docker/env.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"TEILER_DASHBOARD_HTTP_RELATIVE_PATH": "${TEILER_DASHBOARD_HTTP_RELATIVE_PATH}",
"TEILER_ORCHESTRATOR_HTTP_RELATIVE_PATH": "${TEILER_ORCHESTRATOR_HTTP_RELATIVE_PATH}",
"REPORTER_DEFAULT_TEMPLATE_ID": "${REPORTER_DEFAULT_TEMPLATE_ID}",
"EXPORTER_DEFAULT_TEMPLATE_ID": "${EXPORTER_DEFAULT_TEMPLATE_ID}"
"EXPORTER_DEFAULT_TEMPLATE_ID": "${EXPORTER_DEFAULT_TEMPLATE_ID}",
"TEILER_USER": "${TEILER_USER}",
"TEILER_ADMIN": "${TEILER_ADMIN}"
};

})(this);
13 changes: 13 additions & 0 deletions src/app/security/teiler-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ export class TeilerAuthService {
return this.keycloakService.loadUserProfile();
}

public getGroups(): string[] {
const keycloakInstance = this.keycloakService.getKeycloakInstance();
const result = keycloakInstance?.tokenParsed?.['groups'] || [];

return result.map((group: string) => {
if (typeof group === 'string' && group.charAt(0) === '/') {
return group.substring(1); // Remove the first character if it's '/'
}
return group;
});
}


}
19 changes: 16 additions & 3 deletions src/app/teiler/teiler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ export class TeilerService {
let teilerAppRoles = new Set(teilerApp.roles);
if (teilerAppRoles.size == 0) {
isAuthorized = true;
} else if (teilerAppRoles.has(TeilerRole.TEILER_PUBLIC) && this.authService.getRoles().length == 0) {
//} else if (teilerAppRoles.has(TeilerRole.TEILER_PUBLIC) && this.authService.getRoles().length == 0) {
} else if (teilerAppRoles.has(TeilerRole.TEILER_PUBLIC)) {
isAuthorized = true;
} else {
for (let role of this.authService.getRoles()) {
if (teilerAppRoles.has(TeilerRole[role as keyof typeof TeilerRole])) {
//for (let role of this.authService.getRoles()) {
for (let role of this.authService.getGroups()) {
let mappedRole = this.fetchRoleFromEnvironment(role);
if (mappedRole != undefined && teilerAppRoles.has(mappedRole)) {
return true;
}
}
Expand All @@ -106,6 +109,16 @@ export class TeilerService {
return isAuthorized;
}

fetchRoleFromEnvironment(role: string): TeilerRole | undefined {
if (role === environment.config.TEILER_USER) {
return TeilerRole.TEILER_USER;
} else if (role === environment.config.TEILER_ADMIN) {
return TeilerRole.TEILER_ADMIN;
} else {
return undefined; // Role doesn't match any enum values
}
}

addTeilerDashboardApps(teilerDashboardApps: TeilerApp[]) {

let embeddedTeilerAppsMap = new Map(this.allTeilerApps.map(teilerApp => [teilerApp.name, teilerApp]));
Expand Down
10 changes: 6 additions & 4 deletions src/assets/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
window["env"]["teiler"]["config"] = {
"DEFAULT_LANGUAGE": "DE",
"TEILER_BACKEND_URL": "http://localhost:8085",
"KEYCLOAK_URL": "http://localhost:8380/login",
"KEYCLOAK_REALM": "teiler",
"KEYCLOAK_CLIENT_ID": "teiler",
"KEYCLOAK_URL": "https://login.verbis.dkfz.de",
"KEYCLOAK_REALM": "test-realm-01",
"KEYCLOAK_CLIENT_ID": "bridgehead-test",
"TEILER_ADMIN_NAME": "Max Mustermann",
"TEILER_ADMIN_EMAIL": "[email protected]",
"TEILER_ADMIN_PHONE": "+49 123 456789",
Expand All @@ -17,7 +17,9 @@
"TEILER_DASHBOARD_HTTP_RELATIVE_PATH": "",
"TEILER_ORCHESTRATOR_HTTP_RELATIVE_PATH": "",
"REPORTER_DEFAULT_TEMPLATE_ID": "ccp-qb",
"EXPORTER_DEFAULT_TEMPLATE_ID": "ccp"
"EXPORTER_DEFAULT_TEMPLATE_ID": "ccp",
"TEILER_USER": "bridgehead-test",
"TEILER_ADMIN": "bridgehead-test-admin"
};

})(this);

0 comments on commit 45ca734

Please sign in to comment.