Skip to content

Commit

Permalink
SONAR-17511 fix wrong behavior of the SAML Groups field when no value…
Browse files Browse the repository at this point in the history
… is provided.
  • Loading branch information
matteo-mara-sonarsource authored and sonartech committed Oct 27, 2022
1 parent b9347f0 commit 530635f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public UserIdentity buildUserIdentity(OAuth2IdentityProvider.CallbackContext con
.setProviderLogin(login)
.setName(this.getName(auth));
this.getEmail(auth).ifPresent(userIdentityBuilder::setEmail);
userIdentityBuilder.setGroups(this.getGroups(auth));
this.getGroups(auth).ifPresent(userIdentityBuilder::setGroups);

return userIdentityBuilder.build();
}
Expand Down Expand Up @@ -169,8 +169,8 @@ private Optional<String> getEmail(Auth auth) {
return samlSettings.getUserEmail().map(userEmailField -> getFirstAttribute(auth, userEmailField));
}

private Set<String> getGroups(Auth auth) {
return samlSettings.getGroupName().map(groupsField -> getGroups(auth, groupsField)).orElse(emptySet());
private Optional<Set<String>> getGroups(Auth auth) {
return samlSettings.getGroupName().map(groupsField -> getGroups(auth, groupsField));
}

private static String getNonNullFirstAttribute(Auth auth, String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public void callback_does_not_sync_group_when_group_setting_is_not_set() {

assertThat(callbackContext.userIdentity.getProviderLogin()).isEqualTo("johndoe");
assertThat(callbackContext.userIdentity.getGroups()).isEmpty();
assertThat(callbackContext.userIdentity.shouldSyncGroups()).isFalse();
}

@Test
Expand Down

0 comments on commit 530635f

Please sign in to comment.