Renamed registration to default roles, add default roles to all users when they are created
This commit is contained in:
parent
c5366f1c81
commit
070c0ddba4
16 changed files with 48 additions and 33 deletions
|
@ -82,8 +82,8 @@ module.config([ '$routeProvider', function($routeProvider) {
|
||||||
},
|
},
|
||||||
controller : 'RealmSocialCtrl'
|
controller : 'RealmSocialCtrl'
|
||||||
})
|
})
|
||||||
.when('/realms/:realm/registration-settings', {
|
.when('/realms/:realm/default-roles', {
|
||||||
templateUrl : 'partials/realm-registration.html',
|
templateUrl : 'partials/realm-default-roles.html',
|
||||||
resolve : {
|
resolve : {
|
||||||
realm : function(RealmLoader) {
|
realm : function(RealmLoader) {
|
||||||
return RealmLoader();
|
return RealmLoader();
|
||||||
|
@ -95,7 +95,7 @@ module.config([ '$routeProvider', function($routeProvider) {
|
||||||
return RoleListLoader();
|
return RoleListLoader();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
controller : 'RealmRegistrationCtrl'
|
controller : 'RealmDefaultRolesCtrl'
|
||||||
})
|
})
|
||||||
.when('/realms/:realm/required-credentials', {
|
.when('/realms/:realm/required-credentials', {
|
||||||
templateUrl : 'partials/realm-credentials.html',
|
templateUrl : 'partials/realm-credentials.html',
|
||||||
|
|
|
@ -427,9 +427,9 @@ module.controller('RealmRequiredCredentialsCtrl', function($scope, Realm, realm,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('RealmRegistrationCtrl', function ($scope, Realm, realm, applications, roles, Notifications, ApplicationRole, Application) {
|
module.controller('RealmDefaultRolesCtrl', function ($scope, Realm, realm, applications, roles, Notifications, ApplicationRole, Application) {
|
||||||
|
|
||||||
console.log('RealmRegistrationCtrl');
|
console.log('RealmDefaultRolesCtrl');
|
||||||
|
|
||||||
$scope.realm = realm;
|
$scope.realm = realm;
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li class="active"><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li class="active"><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li class="active"><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li class="active"><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li class="active" data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li class="active" data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li class="active"><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li class="active"><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<ul class="rcue-tabs">
|
<ul class="rcue-tabs">
|
||||||
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
<li><a href="#/realms/{{realm.realm}}">General</a></li>
|
||||||
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
<li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
|
||||||
<li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
|
|
||||||
<li class="active"><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
<li class="active"><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
|
||||||
|
<li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
<li><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
<li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
|
||||||
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
<li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
|
||||||
|
|
|
@ -444,7 +444,19 @@ public class RealmAdapter implements RealmModel {
|
||||||
entity.setRealm(realm);
|
entity.setRealm(realm);
|
||||||
em.persist(entity);
|
em.persist(entity);
|
||||||
em.flush();
|
em.flush();
|
||||||
return new UserAdapter(entity);
|
UserModel userModel = new UserAdapter(entity);
|
||||||
|
|
||||||
|
for (String r : getDefaultRoles()) {
|
||||||
|
grantRole(userModel, getRole(r));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ApplicationModel application : getApplications()) {
|
||||||
|
for (String r : application.getDefaultRoles()) {
|
||||||
|
application.grantRole(userModel, application.getRole(r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return userModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -516,7 +516,19 @@ public class RealmAdapter implements RealmModel {
|
||||||
if (user != null) throw new IllegalStateException("User already exists");
|
if (user != null) throw new IllegalStateException("User already exists");
|
||||||
user = new User(username);
|
user = new User(username);
|
||||||
getIdm().add(user);
|
getIdm().add(user);
|
||||||
return new UserAdapter(user, getIdm());
|
UserAdapter userModel = new UserAdapter(user, getIdm());
|
||||||
|
|
||||||
|
for (String r : getDefaultRoles()) {
|
||||||
|
grantRole(userModel, getRole(r));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ApplicationModel application : getApplications()) {
|
||||||
|
for (String r : application.getDefaultRoles()) {
|
||||||
|
application.grantRole(userModel, application.getRole(r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return userModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -885,7 +897,7 @@ public class RealmAdapter implements RealmModel {
|
||||||
@Override
|
@Override
|
||||||
public Set<SocialLinkModel> getSocialLinks(UserModel user) {
|
public Set<SocialLinkModel> getSocialLinks(UserModel user) {
|
||||||
RelationshipQuery<SocialLinkRelationship> query = getRelationshipManager().createRelationshipQuery(SocialLinkRelationship.class);
|
RelationshipQuery<SocialLinkRelationship> query = getRelationshipManager().createRelationshipQuery(SocialLinkRelationship.class);
|
||||||
query.setParameter(SocialLinkRelationship.USER, ((UserAdapter)user).getUser());
|
query.setParameter(SocialLinkRelationship.USER, ((UserAdapter) user).getUser());
|
||||||
List<SocialLinkRelationship> plSocialLinks = query.getResultList();
|
List<SocialLinkRelationship> plSocialLinks = query.getResultList();
|
||||||
|
|
||||||
Set<SocialLinkModel> results = new HashSet<SocialLinkModel>();
|
Set<SocialLinkModel> results = new HashSet<SocialLinkModel>();
|
||||||
|
|
|
@ -339,16 +339,6 @@ public class TokenService {
|
||||||
realm.updateCredential(user, credentials);
|
realm.updateCredential(user, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String r : realm.getDefaultRoles()) {
|
|
||||||
realm.grantRole(user, realm.getRole(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ApplicationModel application : realm.getApplications()) {
|
|
||||||
for (String r : application.getDefaultRoles()) {
|
|
||||||
application.grantRole(user, application.getRole(r));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return processLogin(clientId, scopeParam, state, redirect, formData);
|
return processLogin(clientId, scopeParam, state, redirect, formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,12 +54,12 @@ public class ProfileTest {
|
||||||
user.setAttribute("key2", "value2");
|
user.setAttribute("key2", "value2");
|
||||||
|
|
||||||
ApplicationModel accountApp = appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
|
ApplicationModel accountApp = appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
|
||||||
for (String r : accountApp.getDefaultRoles()) {
|
|
||||||
accountApp.grantRole(user, accountApp.getRole(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
UserModel user2 = appRealm.addUser("test-user-no-access@localhost");
|
UserModel user2 = appRealm.addUser("test-user-no-access@localhost");
|
||||||
user2.setEnabled(true);
|
user2.setEnabled(true);
|
||||||
|
for (String r : accountApp.getDefaultRoles()) {
|
||||||
|
accountApp.deleteRoleMapping(user2, accountApp.getRole(r));
|
||||||
|
}
|
||||||
UserCredentialModel creds = new UserCredentialModel();
|
UserCredentialModel creds = new UserCredentialModel();
|
||||||
creds.setType(CredentialRepresentation.PASSWORD);
|
creds.setType(CredentialRepresentation.PASSWORD);
|
||||||
creds.setValue("password");
|
creds.setValue("password");
|
||||||
|
|
|
@ -52,13 +52,14 @@ public class AccountTest {
|
||||||
@Override
|
@Override
|
||||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
UserModel user = appRealm.getUser("test-user@localhost");
|
UserModel user = appRealm.getUser("test-user@localhost");
|
||||||
|
|
||||||
ApplicationModel accountApp = appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
|
ApplicationModel accountApp = appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
|
||||||
for (String r : accountApp.getDefaultRoles()) {
|
|
||||||
accountApp.grantRole(user, accountApp.getRole(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
UserModel user2 = appRealm.addUser("test-user-no-access@localhost");
|
UserModel user2 = appRealm.addUser("test-user-no-access@localhost");
|
||||||
user2.setEnabled(true);
|
user2.setEnabled(true);
|
||||||
|
for (String r : accountApp.getDefaultRoles()) {
|
||||||
|
accountApp.deleteRoleMapping(user2, accountApp.getRole(r));
|
||||||
|
}
|
||||||
UserCredentialModel creds = new UserCredentialModel();
|
UserCredentialModel creds = new UserCredentialModel();
|
||||||
creds.setType(CredentialRepresentation.PASSWORD);
|
creds.setType(CredentialRepresentation.PASSWORD);
|
||||||
creds.setValue("password");
|
creds.setValue("password");
|
||||||
|
|
Loading…
Reference in a new issue