Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OIDC group/role mapping #573

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,14 @@ akhq:
google:
label: "Login with Google"
username-field: preferred_username
# specifies the field name in the oidc claim containig the use assigned role (eg. in keycloak this would be the Token Claim Name you set in your Client Role Mapper)
groups-field: roles
default-group: topic-reader
groups:
# the name of the user role set in your oidc provider and associated with your user (eg. in keycloak this would be a client role)
- name: mathematicians
groups:
# the corresponding akhq groups (eg. topic-reader/writer or akhq default groups like admin/reader/no-role)
- topic-reader
- name: scientists
groups:
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/akhq/modules/OidcUserDetailsMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public UserDetails createUserDetails(String providerName, OpenIdTokenResponse to
List<String> akhqGroups = getAkhqGroups(providerName, openIdClaims, username);
List<String> roles = userGroupUtils.getUserRoles(akhqGroups);
Map<String, Object> attributes = buildAttributes(providerName, tokenResponse, openIdClaims, akhqGroups);

/**
* In case of OIDC the user roles are not correctly mapped to corresponding roles in akhq,
* If we find a groups-field in the user attributes override it with the correctly mapped
* roles that match the associated akhq group
*/
Oidc.Provider provider = oidc.getProvider(providerName);
if (attributes.containsKey(provider.getGroupsField())) {
attributes.put(provider.getGroupsField(), roles);
}
return new UserDetails(username, roles, attributes);
}
}