KEYCLOAK-2610 Ommit checks for default roles and groups during creation of user
This commit is contained in:
parent
16ec76e864
commit
c973dc9eee
2 changed files with 13 additions and 4 deletions
|
@ -76,21 +76,21 @@ public class JpaUserProvider implements UserProvider {
|
||||||
entity.setRealmId(realm.getId());
|
entity.setRealmId(realm.getId());
|
||||||
em.persist(entity);
|
em.persist(entity);
|
||||||
em.flush();
|
em.flush();
|
||||||
UserModel userModel = new UserAdapter(session, realm, em, entity);
|
UserAdapter userModel = new UserAdapter(session, realm, em, entity);
|
||||||
|
|
||||||
if (addDefaultRoles) {
|
if (addDefaultRoles) {
|
||||||
for (String r : realm.getDefaultRoles()) {
|
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 (ClientModel application : realm.getClients()) {
|
||||||
for (String r : application.getDefaultRoles()) {
|
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()) {
|
for (GroupModel g : realm.getDefaultGroups()) {
|
||||||
userModel.joinGroup(g);
|
userModel.joinGroupImpl(g); // No need to check if user has group as it's new user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -517,6 +517,11 @@ public class UserAdapter implements UserModel, JpaModel<UserEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void joinGroup(GroupModel group) {
|
public void joinGroup(GroupModel group) {
|
||||||
if (isMemberOf(group)) return;
|
if (isMemberOf(group)) return;
|
||||||
|
joinGroupImpl(group);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void joinGroupImpl(GroupModel group) {
|
||||||
UserGroupMembershipEntity entity = new UserGroupMembershipEntity();
|
UserGroupMembershipEntity entity = new UserGroupMembershipEntity();
|
||||||
entity.setUser(getEntity());
|
entity.setUser(getEntity());
|
||||||
entity.setGroupId(group.getId());
|
entity.setGroupId(group.getId());
|
||||||
|
@ -570,6 +575,10 @@ public class UserAdapter implements UserModel, JpaModel<UserEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void grantRole(RoleModel role) {
|
public void grantRole(RoleModel role) {
|
||||||
if (hasRole(role)) return;
|
if (hasRole(role)) return;
|
||||||
|
grantRoleImpl(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void grantRoleImpl(RoleModel role) {
|
||||||
UserRoleMappingEntity entity = new UserRoleMappingEntity();
|
UserRoleMappingEntity entity = new UserRoleMappingEntity();
|
||||||
entity.setUser(getEntity());
|
entity.setUser(getEntity());
|
||||||
entity.setRoleId(role.getId());
|
entity.setRoleId(role.getId());
|
||||||
|
|
Loading…
Reference in a new issue