-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allowedGroups to UserConfig in IdZ configuration (#2606)
* fix sonar issue: Utility classes should not have public constructors * fix: possibly unnecessary method call * fix: define Java version * handle in separate PR * feature: add attribute userConfig.allowedGroups to IdZ * revert format changes * revert format changes * fix Sonar warnings * remove TODO * create new needed bean similar than the other beans created * is an optional entry in identity zone configuration * fix sonar smells * combine default and allowed groups * fix Sonar warnings * add test class * add testResultingAllowedGroups * add testScopesIncludesAllowedAuthoritiesForUser * zoneId must not be null * use right asserts * remove null-check * add integration tests * fix createNotAllowedGroupFails * introduce list allowedGroups * update allowedGroups on server * pass IdZ id * determine zone id * update integration tests We have 4 tests 2 positive and 2 negative 2 using allowedGroups 2 relying on defaultGroups because allowedGroups is empty * cleanup in integration tests, fixes mftop refactor to omit dublicates * change log level to info * remove log message * check for groups which would be not allowed after the update * must not remove default group from configuration * remove sonar comment --------- Co-authored-by: Markus Strehle <11627201+strehle@users.noreply.github.com> Co-authored-by: d036670 <markus.strehle@sap.com>
- Loading branch information
1 parent
ee33241
commit 63ad5f3
Showing
24 changed files
with
449 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
model/src/test/java/org/cloudfoundry/identity/uaa/zone/UserConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.cloudfoundry.identity.uaa.zone; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.Test; | ||
|
||
public class UserConfigTest { | ||
|
||
@Test | ||
public void testDefaultConfig() { | ||
UserConfig userConfig = new UserConfig(); | ||
assertTrue(userConfig.getDefaultGroups().contains("openid")); | ||
assertNull(userConfig.getAllowedGroups()); // all groups allowed | ||
assertNull(userConfig.resultingAllowedGroups()); // all groups allowed | ||
} | ||
|
||
@Test | ||
public void testResultingAllowedGroups() { | ||
UserConfig userConfig = new UserConfig(); | ||
userConfig.setDefaultGroups(List.of("openid")); | ||
userConfig.setAllowedGroups(List.of("uaa.user")); | ||
assertEquals(List.of("openid"), userConfig.getDefaultGroups()); | ||
assertEquals(List.of("uaa.user"), userConfig.getAllowedGroups()); | ||
assertEquals(Set.of("openid", "uaa.user"), userConfig.resultingAllowedGroups()); | ||
} | ||
|
||
@Test | ||
public void testNoDefaultGroups() { | ||
UserConfig userConfig = new UserConfig(); | ||
userConfig.setDefaultGroups(null); | ||
userConfig.setAllowedGroups(List.of("uaa.user")); | ||
assertNull(userConfig.getDefaultGroups()); | ||
assertEquals(List.of("uaa.user"), userConfig.getAllowedGroups()); | ||
assertEquals(Set.of("uaa.user"), userConfig.resultingAllowedGroups()); | ||
} | ||
|
||
@Test | ||
public void testNoDefaultAndNoAllowedGroups() { | ||
UserConfig userConfig = new UserConfig(); | ||
userConfig.setDefaultGroups(null); | ||
userConfig.setAllowedGroups(null); | ||
assertNull(userConfig.getDefaultGroups()); | ||
assertNull(userConfig.getAllowedGroups()); // all groups allowed | ||
assertNull(userConfig.resultingAllowedGroups()); // all groups allowed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
server/src/main/java/org/cloudfoundry/identity/uaa/zone/UserConfigValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.cloudfoundry.identity.uaa.zone; | ||
|
||
import java.util.Set; | ||
|
||
public class UserConfigValidator { | ||
|
||
// add a private constructor to hide the implicit public one | ||
private UserConfigValidator() { | ||
} | ||
|
||
public static void validate(UserConfig config) throws InvalidIdentityZoneConfigurationException { | ||
Set<String> allowedGroups = (config == null) ? null : config.resultingAllowedGroups(); | ||
if ((allowedGroups != null) && (allowedGroups.isEmpty())) { | ||
String message = "At least one group must be allowed"; | ||
throw new InvalidIdentityZoneConfigurationException(message); | ||
} | ||
} | ||
} |
Oops, something went wrong.