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

Fix: sync even if the user has no groups (to remove roles the user had) #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,10 @@ private void syncGroups(RealmModel realm, UserModel user, IdentityProviderMapper

// get new groups
Object newGroupsObj = getClaimValue(context, groupClaimName);
// don't modify groups membership if the claim was not found
// useful to sync even if the user has no groups (remove roles the user had)
if (newGroupsObj == null) {
logger.debugf("Realm [%s], IdP [%s]: no group claim (claim name: [%s]) for user [%s], ignoring...",
realm.getName(),
mapperModel.getIdentityProviderAlias(),
groupClaimName,
user.getUsername());
return;
List<String> newList = new ArrayList<>();
newGroupsObj = newList;
}

logger.debugf("Realm [%s], IdP [%s]: starting mapping groups for user [%s]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ protected String getProfileEndpointForValidation(EventBuilder event) {

@Override
protected BrokeredIdentityContext extractIdentityFromProfile(EventBuilder event, JsonNode profile) {
BrokeredIdentityContext user = new BrokeredIdentityContext(getJsonProperty(profile, "id"));
String id = getJsonProperty(profile, "id");
BrokeredIdentityContext user = new BrokeredIdentityContext(id);

String username = getJsonProperty(profile, "username");
String discriminator = getJsonProperty(profile, "discriminator");
// String discriminator = getJsonProperty(profile, "discriminator");

if (!"0".equals(discriminator)) {
username += "#" + discriminator;
}
// if (!"0".equals(discriminator)) {
// username += "#" + discriminator;
// }
username = username + " (" + id + ")";

user.setUsername(username);
user.setEmail(getJsonProperty(profile, "email"));
Expand Down