Username now shown when creating a user and edit username is not allowed
Closes #24183
This commit is contained in:
parent
f4d1dd9b7f
commit
e47389f199
2 changed files with 37 additions and 2 deletions
|
@ -77,7 +77,9 @@ public abstract class AbstractUserProfileProvider<U extends UserProfileProvider>
|
|||
KeycloakContext context = session.getContext();
|
||||
RealmModel realm = context.getRealm();
|
||||
|
||||
if (REGISTRATION.equals(c.getContext()) || IDP_REVIEW.equals(c.getContext())) {
|
||||
if (REGISTRATION.equals(c.getContext())
|
||||
|| IDP_REVIEW.equals(c.getContext())
|
||||
|| isNewUser(c)) {
|
||||
return !realm.isRegistrationEmailAsUsername();
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ public class UserProfileAdminTest extends AbstractAdminTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUsernameRequiredIfEmailAsUsernameDisabled() {
|
||||
public void testUsernameRequiredAndWritableIfEmailAsUsernameDisabledAndEditUsernameAllowed() {
|
||||
RealmResource realm = testRealm();
|
||||
RealmRepresentation realmRep = realm.toRepresentation();
|
||||
Boolean registrationEmailAsUsername = realmRep.isRegistrationEmailAsUsername();
|
||||
|
@ -118,9 +118,41 @@ public class UserProfileAdminTest extends AbstractAdminTest {
|
|||
realmRep.setRegistrationEmailAsUsername(registrationEmailAsUsername);
|
||||
realm.update(realmRep);
|
||||
});
|
||||
Boolean editUsernameAllowed = realmRep.isEditUsernameAllowed();
|
||||
realmRep.setEditUsernameAllowed(true);
|
||||
realm.update(realmRep);
|
||||
getCleanup().addCleanup(() -> {
|
||||
realmRep.setEditUsernameAllowed(editUsernameAllowed);
|
||||
realm.update(realmRep);
|
||||
});
|
||||
UserProfileResource userProfile = realm.users().userProfile();
|
||||
UserProfileMetadata metadata = userProfile.getMetadata();
|
||||
assertTrue(metadata.getAttributeMetadata(UserModel.USERNAME).isRequired());
|
||||
assertFalse(metadata.getAttributeMetadata(UserModel.USERNAME).isReadOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsernameRequiredAndWritableIfEmailAsUsernameDisabledAndEditUsernameDisabled() {
|
||||
RealmResource realm = testRealm();
|
||||
RealmRepresentation realmRep = realm.toRepresentation();
|
||||
Boolean registrationEmailAsUsername = realmRep.isRegistrationEmailAsUsername();
|
||||
realmRep.setRegistrationEmailAsUsername(false);
|
||||
realm.update(realmRep);
|
||||
getCleanup().addCleanup(() -> {
|
||||
realmRep.setRegistrationEmailAsUsername(registrationEmailAsUsername);
|
||||
realm.update(realmRep);
|
||||
});
|
||||
Boolean editUsernameAllowed = realmRep.isEditUsernameAllowed();
|
||||
realmRep.setEditUsernameAllowed(false);
|
||||
realm.update(realmRep);
|
||||
getCleanup().addCleanup(() -> {
|
||||
realmRep.setEditUsernameAllowed(editUsernameAllowed);
|
||||
realm.update(realmRep);
|
||||
});
|
||||
UserProfileResource userProfile = realm.users().userProfile();
|
||||
UserProfileMetadata metadata = userProfile.getMetadata();
|
||||
assertTrue(metadata.getAttributeMetadata(UserModel.USERNAME).isRequired());
|
||||
assertFalse(metadata.getAttributeMetadata(UserModel.USERNAME).isReadOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -137,6 +169,7 @@ public class UserProfileAdminTest extends AbstractAdminTest {
|
|||
UserProfileResource userProfile = realm.users().userProfile();
|
||||
UserProfileMetadata metadata = userProfile.getMetadata();
|
||||
assertFalse(metadata.getAttributeMetadata(UserModel.USERNAME).isRequired());
|
||||
assertTrue(metadata.getAttributeMetadata(UserModel.USERNAME).isReadOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue