]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17511 fix wrong behavior of the SAML Groups field when no value is provided.
authorMatteo Mara <matteo.mara@sonarsource.com>
Mon, 24 Oct 2022 16:05:44 +0000 (18:05 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 27 Oct 2022 20:03:06 +0000 (20:03 +0000)
server/sonar-auth-saml/src/main/java/org/sonar/auth/saml/SamlAuthenticator.java
server/sonar-auth-saml/src/test/java/org/sonar/auth/saml/SamlIdentityProviderTest.java

index dba3c5b170f55dc3b978c36016b22641ae559461..3ad4326004dc412cf58940421fe18c023af17a80 100644 (file)
@@ -78,7 +78,7 @@ public class SamlAuthenticator {
       .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();
   }
@@ -169,8 +169,8 @@ public class SamlAuthenticator {
     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) {
index 5fdc4a9485eaf466c680a5256fd3bde27453d46c..13122e38cae21c5f06e68b7346f47eb9ae1e0e6e 100644 (file)
@@ -247,6 +247,7 @@ public class SamlIdentityProviderTest {
 
     assertThat(callbackContext.userIdentity.getProviderLogin()).isEqualTo("johndoe");
     assertThat(callbackContext.userIdentity.getGroups()).isEmpty();
+    assertThat(callbackContext.userIdentity.shouldSyncGroups()).isFalse();
   }
 
   @Test