KEYCLOAK-2610 Ommit checks for default roles and groups during creation of user

This commit is contained in:
mposolda 2016-03-24 10:46:09 +01:00
parent 16ec76e864
commit c973dc9eee
2 changed files with 13 additions and 4 deletions

View file

@ -76,21 +76,21 @@ public class JpaUserProvider implements UserProvider {
entity.setRealmId(realm.getId());
em.persist(entity);
em.flush();
UserModel userModel = new UserAdapter(session, realm, em, entity);
UserAdapter userModel = new UserAdapter(session, realm, em, entity);
if (addDefaultRoles) {
for (String r : realm.getDefaultRoles()) {
userModel.grantRole(realm.getRole(r));
userModel.grantRoleImpl(realm.getRole(r)); // No need to check if user has role as it's new user
}
for (ClientModel application : realm.getClients()) {
for (String r : application.getDefaultRoles()) {
userModel.grantRole(application.getRole(r));
userModel.grantRoleImpl(application.getRole(r)); // No need to check if user has role as it's new user
}
}
for (GroupModel g : realm.getDefaultGroups()) {
userModel.joinGroup(g);
userModel.joinGroupImpl(g); // No need to check if user has group as it's new user
}
}

View file

@ -517,6 +517,11 @@ public class UserAdapter implements UserModel, JpaModel<UserEntity> {
@Override
public void joinGroup(GroupModel group) {
if (isMemberOf(group)) return;
joinGroupImpl(group);
}
protected void joinGroupImpl(GroupModel group) {
UserGroupMembershipEntity entity = new UserGroupMembershipEntity();
entity.setUser(getEntity());
entity.setGroupId(group.getId());
@ -570,6 +575,10 @@ public class UserAdapter implements UserModel, JpaModel<UserEntity> {
@Override
public void grantRole(RoleModel role) {
if (hasRole(role)) return;
grantRoleImpl(role);
}
public void grantRoleImpl(RoleModel role) {
UserRoleMappingEntity entity = new UserRoleMappingEntity();
entity.setUser(getEntity());
entity.setRoleId(role.getId());