Do not reset the user profile configuration on disable

Closes https://github.com/keycloak/keycloak/issues/23527
This commit is contained in:
rmartinc 2023-10-21 10:06:48 +02:00 committed by Pedro Igor
parent e567210ed1
commit ad01ed1497
3 changed files with 26 additions and 10 deletions

View file

@ -706,11 +706,6 @@ public class LegacyExportImportManager implements ExportImportManager {
renameRealm(realm, rep.getRealm());
}
if (!Boolean.parseBoolean(rep.getAttributesOrEmpty().get("userProfileEnabled"))) {
UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
provider.setConfiguration(null);
}
// Import attributes first, so the stuff saved directly on representation (displayName, bruteForce etc) has bigger priority
if (rep.getAttributes() != null) {
Set<String> attrsToRemove = new HashSet<>(realm.getAttributes().keySet());

View file

@ -995,11 +995,6 @@ public class MapExportImportManager implements ExportImportManager {
renameRealm(realm, rep.getRealm());
}
if (!Boolean.parseBoolean(rep.getAttributesOrEmpty().get("userProfileEnabled"))) {
UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
provider.setConfiguration(null);
}
// Import attributes first, so the stuff saved directly on representation (displayName, bruteForce etc) has bigger priority
if (rep.getAttributes() != null) {
Set<String> attrsToRemove = new HashSet<>(realm.getAttributes().keySet());

View file

@ -1143,6 +1143,25 @@ public class VerifyProfileTest extends AbstractTestRealmKeycloakTest {
Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));
}
@Test
public void testConfigurationRemainsAfterReset() {
String customConfig = "{\"attributes\": ["
+ "{\"name\": \"firstName\"," + PERMISSIONS_ALL + ", \"required\": {}},"
+ "{\"name\": \"lastName\"," + PERMISSIONS_ALL + "},"
+ "{\"name\": \"department\"," + PERMISSIONS_ALL + ", " + VALIDATIONS_LENGTH + "}"
+ "]}";
setUserProfileConfiguration(customConfig);
RealmResource realmRes = testRealm();
disableDynamicUserProfile(realmRes, false);
RealmRepresentation realm = realmRes.toRepresentation();
enableDynamicUserProfile(realm);
testRealm().update(realm);
Assert.assertEquals(customConfig, realmRes.users().userProfile().getConfiguration());
}
protected UserRepresentation getUser(String userId) {
return getUser(testRealm(), userId);
}
@ -1171,12 +1190,19 @@ public class VerifyProfileTest extends AbstractTestRealmKeycloakTest {
}
public static void disableDynamicUserProfile(RealmResource realm) {
disableDynamicUserProfile(realm, true);
}
public static void disableDynamicUserProfile(RealmResource realm, boolean reset) {
RealmRepresentation realmRep = realm.toRepresentation();
if (realmRep.getAttributes() == null) {
realmRep.setAttributes(new HashMap<>());
}
realmRep.getAttributes().put(REALM_USER_PROFILE_ENABLED, Boolean.FALSE.toString());
realm.update(realmRep);
if (reset) {
setUserProfileConfiguration(realm, null);
}
}