KEYCLOAK-16112 don't remove username attribute
This commit is contained in:
parent
200b53ed1e
commit
f4abc86a66
2 changed files with 31 additions and 2 deletions
|
@ -213,8 +213,11 @@ public class UserAttributeLDAPStorageMapper extends AbstractLDAPStorageMapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAttribute(String name) {
|
public void removeAttribute(String name) {
|
||||||
if (setLDAPAttribute(name, null)) {
|
if(!UserModel.USERNAME.equals(name)){
|
||||||
super.removeAttribute(name);
|
//do not remove username
|
||||||
|
if (setLDAPAttribute(name, null)) {
|
||||||
|
super.removeAttribute(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,32 @@ public class LDAPAccountRestApiTest extends AbstractLDAPTest {
|
||||||
Assert.assertNull(userPassword.getSecretData());
|
Assert.assertNull(userPassword.getSecretData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateProfile() throws IOException {
|
||||||
|
testingClient.server().run(session -> {
|
||||||
|
LDAPTestContext ctx = LDAPTestContext.init(session);
|
||||||
|
RealmModel appRealm = ctx.getRealm();
|
||||||
|
appRealm.setEditUsernameAllowed(false);
|
||||||
|
});
|
||||||
|
UserRepresentation user = SimpleHttp.doGet(getAccountUrl(null), httpClient).auth(tokenUtil.getToken()).asJson(UserRepresentation.class);
|
||||||
|
user.setEmail("john-alias@email.org");
|
||||||
|
SimpleHttp.doPost(getAccountUrl(null), httpClient).json(user).auth(tokenUtil.getToken()).asStatus();
|
||||||
|
|
||||||
|
UserRepresentation usernew = SimpleHttp.doGet(getAccountUrl(null), httpClient).auth(tokenUtil.getToken()).asJson(UserRepresentation.class);
|
||||||
|
assertEquals("johnkeycloak", usernew.getUsername());
|
||||||
|
assertEquals("John", usernew.getFirstName());
|
||||||
|
assertEquals("Doe", usernew.getLastName());
|
||||||
|
assertEquals("john-alias@email.org", usernew.getEmail());
|
||||||
|
assertFalse(usernew.isEmailVerified());
|
||||||
|
|
||||||
|
//clean up
|
||||||
|
usernew.setEmail("john@email.org");
|
||||||
|
SimpleHttp.doPost(getAccountUrl(null), httpClient).json(usernew).auth(tokenUtil.getToken()).asStatus();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getAccountUrl(String resource) {
|
private String getAccountUrl(String resource) {
|
||||||
return suiteContext.getAuthServerInfo().getContextRoot().toString() + "/auth/realms/test/account" + (resource != null ? "/" + resource : "");
|
return suiteContext.getAuthServerInfo().getContextRoot().toString() + "/auth/realms/test/account" + (resource != null ? "/" + resource : "");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue