Allow username change at first login (KEYCLOAK-1857)
This commit is contained in:
parent
fde4bc99aa
commit
f7a8bbbcc8
3 changed files with 21 additions and 35 deletions
|
@ -6,15 +6,16 @@
|
|||
${msg("loginProfileTitle")}
|
||||
<#elseif section = "form">
|
||||
<form id="kc-update-profile-form" class="${properties.kcFormClass!}" action="${url.loginAction}" method="post">
|
||||
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('username',properties.kcFormGroupErrorClass!)}" <#if !realm.editUsernameAllowed>style="display:none"</#if>>
|
||||
<div class="${properties.kcLabelWrapperClass!}">
|
||||
<label for="username" class="${properties.kcLabelClass!}">${msg("username")}</label>
|
||||
<#if !realm.editUsernameAllowed>
|
||||
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('username',properties.kcFormGroupErrorClass!)}">
|
||||
<div class="${properties.kcLabelWrapperClass!}">
|
||||
<label for="username" class="${properties.kcLabelClass!}">${msg("username")}</label>
|
||||
</div>
|
||||
<div class="${properties.kcInputWrapperClass!}">
|
||||
<input type="text" id="username" name="username" value="${(user.username!'')?html}" class="${properties.kcInputClass!}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="${properties.kcInputWrapperClass!}">
|
||||
<input type="text" id="username" name="username" value="${(user.username!'')?html}" class="${properties.kcInputClass!}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</#if>
|
||||
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('email',properties.kcFormGroupErrorClass!)}">
|
||||
<div class="${properties.kcLabelWrapperClass!}">
|
||||
<label for="email" class="${properties.kcLabelClass!}">${msg("email")}</label>
|
||||
|
|
|
@ -123,10 +123,6 @@ public class AssertEvents implements TestRule, EventListenerProviderFactory {
|
|||
return expectLogin().event(event).removeDetail(Details.CONSENT).session(isUUID());
|
||||
}
|
||||
|
||||
public ExpectedEvent expectRequiredActionEnabledUsername(EventType event, String newUsername) {
|
||||
return expectLogin(newUsername).event(event).removeDetail(Details.CONSENT).session(isUUID());
|
||||
}
|
||||
|
||||
public ExpectedEvent expectLogin() {
|
||||
return expect(EventType.LOGIN)
|
||||
.detail(Details.CODE_ID, isCodeId())
|
||||
|
@ -138,17 +134,6 @@ public class AssertEvents implements TestRule, EventListenerProviderFactory {
|
|||
.session(isUUID());
|
||||
}
|
||||
|
||||
public ExpectedEvent expectLogin(String username) {
|
||||
return expect(EventType.LOGIN, username)
|
||||
.detail(Details.CODE_ID, isCodeId())
|
||||
//.detail(Details.USERNAME, DEFAULT_USERNAME)
|
||||
//.detail(Details.AUTH_METHOD, OIDCLoginProtocol.LOGIN_PROTOCOL)
|
||||
//.detail(Details.AUTH_TYPE, AuthorizationEndpoint.CODE_AUTH_TYPE)
|
||||
.detail(Details.REDIRECT_URI, DEFAULT_REDIRECT_URI)
|
||||
.detail(Details.CONSENT, Details.CONSENT_VALUE_NO_CONSENT_REQUIRED)
|
||||
.session(isUUID());
|
||||
}
|
||||
|
||||
public ExpectedEvent expectClientLogin() {
|
||||
return expect(EventType.CLIENT_LOGIN)
|
||||
.detail(Details.CODE_ID, isCodeId())
|
||||
|
@ -217,16 +202,6 @@ public class AssertEvents implements TestRule, EventListenerProviderFactory {
|
|||
.event(event);
|
||||
}
|
||||
|
||||
public ExpectedEvent expect(EventType event, String username) {
|
||||
return new ExpectedEvent()
|
||||
.realm(DEFAULT_REALM)
|
||||
.client(DEFAULT_CLIENT_ID)
|
||||
.user(keycloak.getUser(DEFAULT_REALM, username).getId())
|
||||
.ipAddress(DEFAULT_IP_ADDRESS)
|
||||
.session((String) null)
|
||||
.event(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventListenerProvider create(KeycloakSession session) {
|
||||
return new EventListenerProvider() {
|
||||
|
|
|
@ -108,15 +108,25 @@ public class RequiredActionUpdateProfileTest {
|
|||
|
||||
loginPage.login("john-doh@localhost", "password");
|
||||
|
||||
String userId = keycloakRule.getUser("test", "john-doh@localhost").getId();
|
||||
|
||||
updateProfilePage.assertCurrent();
|
||||
|
||||
updateProfilePage.update("New first", "New last", "john-doh@localhost", "new");
|
||||
|
||||
String sessionId = events.expectRequiredActionEnabledUsername(EventType.UPDATE_PROFILE, "new").assertEvent().getSessionId();
|
||||
String sessionId = events
|
||||
.expectLogin()
|
||||
.event(EventType.UPDATE_PROFILE)
|
||||
.detail(Details.USERNAME, "john-doh@localhost")
|
||||
.user(userId)
|
||||
.session(AssertEvents.isUUID())
|
||||
.removeDetail(Details.CONSENT)
|
||||
.assertEvent()
|
||||
.getSessionId();
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
events.expectLogin("new").session(sessionId).assertEvent();
|
||||
events.expectLogin().detail(Details.USERNAME, "john-doh@localhost").user(userId).session(sessionId).assertEvent();
|
||||
|
||||
// assert user is really updated in persistent store
|
||||
UserRepresentation user = keycloakRule.getUser("test", "new");
|
||||
|
|
Loading…
Reference in a new issue