Registration page not showing username when edit username is not enabled
Closes #23185
This commit is contained in:
parent
15d2b3abea
commit
1442f14c45
2 changed files with 59 additions and 1 deletions
|
@ -78,7 +78,8 @@ public abstract class AbstractUserProfileProvider<U extends UserProfileProvider>
|
|||
KeycloakContext context = session.getContext();
|
||||
RealmModel realm = context.getRealm();
|
||||
|
||||
if (IDP_REVIEW.equals(c.getContext())) {
|
||||
if (REGISTRATION_PROFILE.equals(c.getContext()) || REGISTRATION_USER_CREATION.equals(c.getContext())
|
||||
|| IDP_REVIEW.equals(c.getContext())) {
|
||||
return !realm.isRegistrationEmailAsUsername();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.keycloak.events.Errors;
|
|||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.AuthenticationExecutionModel;
|
||||
import org.keycloak.models.utils.DefaultAuthenticationFlows;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.representations.idm.EventRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
@ -380,6 +381,62 @@ public class RegisterTest extends AbstractTestRealmKeycloakTest {
|
|||
assertNull(user.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerUserSuccessEditUsernameDisabled() {
|
||||
RealmRepresentation realm = testRealm().toRepresentation();
|
||||
Boolean editUsernameAllowed = realm.isEditUsernameAllowed();
|
||||
Boolean registrationEmailAsUsername = realm.isRegistrationEmailAsUsername();
|
||||
realm.setEditUsernameAllowed(false);
|
||||
realm.setRegistrationEmailAsUsername(false);
|
||||
getCleanup().addCleanup(() -> {
|
||||
realm.setEditUsernameAllowed(editUsernameAllowed);
|
||||
realm.setRegistrationEmailAsUsername(registrationEmailAsUsername);
|
||||
testRealm().update(realm);
|
||||
});
|
||||
testRealm().update(realm);
|
||||
loginPage.open();
|
||||
loginPage.clickRegister();
|
||||
registerPage.assertCurrent();
|
||||
|
||||
String username = KeycloakModelUtils.generateId();
|
||||
String email = username + "@email.com";
|
||||
registerPage.register("firstName", "lastName", email, username, "password", "password");
|
||||
|
||||
appPage.assertCurrent();
|
||||
assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
String userId = events.expectRegister(username, email).assertEvent().getUserId();
|
||||
assertUserRegistered(userId, username, email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerUserSuccessEditUsernameEnabled() {
|
||||
RealmRepresentation realm = testRealm().toRepresentation();
|
||||
Boolean editUsernameAllowed = realm.isEditUsernameAllowed();
|
||||
Boolean registrationEmailAsUsername = realm.isRegistrationEmailAsUsername();
|
||||
realm.setEditUsernameAllowed(true);
|
||||
realm.setRegistrationEmailAsUsername(false);
|
||||
getCleanup().addCleanup(() -> {
|
||||
realm.setEditUsernameAllowed(editUsernameAllowed);
|
||||
realm.setRegistrationEmailAsUsername(registrationEmailAsUsername);
|
||||
testRealm().update(realm);
|
||||
});
|
||||
testRealm().update(realm);
|
||||
loginPage.open();
|
||||
loginPage.clickRegister();
|
||||
registerPage.assertCurrent();
|
||||
|
||||
String username = KeycloakModelUtils.generateId();
|
||||
String email = username + "@email.com";
|
||||
registerPage.register("firstName", "lastName", email, username, "password", "password");
|
||||
|
||||
appPage.assertCurrent();
|
||||
assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
String userId = events.expectRegister(username, email).assertEvent().getUserId();
|
||||
assertUserRegistered(userId, username, email);
|
||||
}
|
||||
|
||||
private void assertUserRegistered(String userId, String username, String email) {
|
||||
events.expectLogin().detail("username", username.toLowerCase()).user(userId).assertEvent();
|
||||
|
||||
|
|
Loading…
Reference in a new issue