split up realm settings

This commit is contained in:
Bill Burke 2013-09-27 15:57:30 -04:00
parent 40d9e7b6f7
commit 86a2617799
12 changed files with 208 additions and 154 deletions

View file

@ -13,7 +13,7 @@ public class AllRoleMappingsRepresentation {
protected String username; protected String username;
protected List<RoleRepresentation> realmMappings; protected List<RoleRepresentation> realmMappings;
protected Map<String, ApplicationRoleMappings> applicationMappings; protected Map<String, ApplicationRoleMappingsRepresentation> applicationMappings;
public String getRealmId() { public String getRealmId() {
return realmId; return realmId;
@ -47,11 +47,11 @@ public class AllRoleMappingsRepresentation {
this.realmMappings = realmMappings; this.realmMappings = realmMappings;
} }
public Map<String,ApplicationRoleMappings> getApplicationMappings() { public Map<String,ApplicationRoleMappingsRepresentation> getApplicationMappings() {
return applicationMappings; return applicationMappings;
} }
public void setApplicationMappings(Map<String, ApplicationRoleMappings> applicationMappings) { public void setApplicationMappings(Map<String, ApplicationRoleMappingsRepresentation> applicationMappings) {
this.applicationMappings = applicationMappings; this.applicationMappings = applicationMappings;
} }
} }

View file

@ -6,7 +6,7 @@ import java.util.List;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class ApplicationRoleMappings { public class ApplicationRoleMappingsRepresentation {
protected String applicationId; protected String applicationId;
protected String application; protected String application;
protected String username; protected String username;

View file

@ -12,17 +12,17 @@ public class RealmRepresentation {
protected String self; // link protected String self; // link
protected String id; protected String id;
protected String realm; protected String realm;
protected int tokenLifespan; protected Integer tokenLifespan;
protected int accessCodeLifespan; protected Integer accessCodeLifespan;
protected int accessCodeLifespanUserAction; protected Integer accessCodeLifespanUserAction;
protected boolean enabled; protected Boolean enabled;
protected boolean sslNotRequired; protected Boolean sslNotRequired;
protected boolean cookieLoginAllowed; protected Boolean cookieLoginAllowed;
protected boolean registrationAllowed; protected Boolean registrationAllowed;
protected boolean verifyEmail; protected Boolean verifyEmail;
protected boolean resetPasswordAllowed; protected Boolean resetPasswordAllowed;
protected boolean social; protected Boolean social;
protected boolean automaticRegistrationAfterSocialLogin; protected Boolean automaticRegistrationAfterSocialLogin;
protected String privateKey; protected String privateKey;
protected String publicKey; protected String publicKey;
protected List<RoleRepresentation> roles; protected List<RoleRepresentation> roles;
@ -93,35 +93,35 @@ public class RealmRepresentation {
this.applications = applications; this.applications = applications;
} }
public boolean isEnabled() { public Boolean isEnabled() {
return enabled; return enabled;
} }
public void setEnabled(boolean enabled) { public void setEnabled(Boolean enabled) {
this.enabled = enabled; this.enabled = enabled;
} }
public boolean isSslNotRequired() { public Boolean isSslNotRequired() {
return sslNotRequired; return sslNotRequired;
} }
public void setSslNotRequired(boolean sslNotRequired) { public void setSslNotRequired(Boolean sslNotRequired) {
this.sslNotRequired = sslNotRequired; this.sslNotRequired = sslNotRequired;
} }
public boolean isCookieLoginAllowed() { public Boolean isCookieLoginAllowed() {
return cookieLoginAllowed; return cookieLoginAllowed;
} }
public void setCookieLoginAllowed(boolean cookieLoginAllowed) { public void setCookieLoginAllowed(Boolean cookieLoginAllowed) {
this.cookieLoginAllowed = cookieLoginAllowed; this.cookieLoginAllowed = cookieLoginAllowed;
} }
public int getTokenLifespan() { public Integer getTokenLifespan() {
return tokenLifespan; return tokenLifespan;
} }
public void setTokenLifespan(int tokenLifespan) { public void setTokenLifespan(Integer tokenLifespan) {
this.tokenLifespan = tokenLifespan; this.tokenLifespan = tokenLifespan;
} }
@ -185,19 +185,19 @@ public class RealmRepresentation {
this.requiredOAuthClientCredentials = requiredOAuthClientCredentials; this.requiredOAuthClientCredentials = requiredOAuthClientCredentials;
} }
public int getAccessCodeLifespan() { public Integer getAccessCodeLifespan() {
return accessCodeLifespan; return accessCodeLifespan;
} }
public void setAccessCodeLifespan(int accessCodeLifespan) { public void setAccessCodeLifespan(Integer accessCodeLifespan) {
this.accessCodeLifespan = accessCodeLifespan; this.accessCodeLifespan = accessCodeLifespan;
} }
public int getAccessCodeLifespanUserAction() { public Integer getAccessCodeLifespanUserAction() {
return accessCodeLifespanUserAction; return accessCodeLifespanUserAction;
} }
public void setAccessCodeLifespanUserAction(int accessCodeLifespanUserAction) { public void setAccessCodeLifespanUserAction(Integer accessCodeLifespanUserAction) {
this.accessCodeLifespanUserAction = accessCodeLifespanUserAction; this.accessCodeLifespanUserAction = accessCodeLifespanUserAction;
} }
@ -233,43 +233,43 @@ public class RealmRepresentation {
this.publicKey = publicKey; this.publicKey = publicKey;
} }
public boolean isRegistrationAllowed() { public Boolean isRegistrationAllowed() {
return registrationAllowed; return registrationAllowed;
} }
public void setRegistrationAllowed(boolean registrationAllowed) { public void setRegistrationAllowed(Boolean registrationAllowed) {
this.registrationAllowed = registrationAllowed; this.registrationAllowed = registrationAllowed;
} }
public boolean isVerifyEmail() { public Boolean isVerifyEmail() {
return verifyEmail; return verifyEmail;
} }
public void setVerifyEmail(boolean verifyEmail) { public void setVerifyEmail(Boolean verifyEmail) {
this.verifyEmail = verifyEmail; this.verifyEmail = verifyEmail;
} }
public boolean isResetPasswordAllowed() { public Boolean isResetPasswordAllowed() {
return resetPasswordAllowed; return resetPasswordAllowed;
} }
public void setResetPasswordAllowed(boolean resetPassword) { public void setResetPasswordAllowed(Boolean resetPassword) {
this.resetPasswordAllowed = resetPassword; this.resetPasswordAllowed = resetPassword;
} }
public boolean isSocial() { public Boolean isSocial() {
return social; return social;
} }
public void setSocial(boolean social) { public void setSocial(Boolean social) {
this.social = social; this.social = social;
} }
public boolean isAutomaticRegistrationAfterSocialLogin() { public Boolean isAutomaticRegistrationAfterSocialLogin() {
return automaticRegistrationAfterSocialLogin; return automaticRegistrationAfterSocialLogin;
} }
public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin) { public void setAutomaticRegistrationAfterSocialLogin(Boolean automaticRegistrationAfterSocialLogin) {
this.automaticRegistrationAfterSocialLogin = automaticRegistrationAfterSocialLogin; this.automaticRegistrationAfterSocialLogin = automaticRegistrationAfterSocialLogin;
} }
} }

View file

@ -26,8 +26,24 @@ module.config([ '$routeProvider', function($routeProvider) {
}).when('/realms', { }).when('/realms', {
templateUrl : 'partials/realm-list.html', templateUrl : 'partials/realm-list.html',
controller : 'RealmListCtrl' controller : 'RealmListCtrl'
}) }).when('/realms/:realm/token-settings', {
templateUrl : 'partials/realm-tokens.html',
resolve : {
realm : function(RealmLoader) {
return RealmLoader();
}
},
controller : 'RealmTokenDetailCtrl'
})
.when('/realms/:realm/required-credentials', {
templateUrl : 'partials/realm-credentials.html',
resolve : {
realm : function(RealmLoader) {
return RealmLoader();
}
},
controller : 'RealmRequiredCredentialsCtrl'
})
.when('/create/user/:realm', { .when('/create/user/:realm', {
templateUrl : 'partials/user-detail.html', templateUrl : 'partials/user-detail.html',
resolve : { resolve : {

View file

@ -64,15 +64,7 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
$scope.realm = { $scope.realm = {
enabled: true, enabled: true,
requireSsl: true, requireSsl: true,
cookieLoginAllowed: true, cookieLoginAllowed: true
tokenLifespan: 300,
tokenLifespanUnit: 'SECONDS',
accessCodeLifespan: 300,
accessCodeLifespanUnit: 'SECONDS',
requiredCredentials: ['password'],
requiredOAuthClientCredentials: ['password'],
requiredApplicationCredentials: ['password']
}; };
} else { } else {
if (Current.realm == null || Current.realm.id != realm.id) { if (Current.realm == null || Current.realm.id != realm.id) {
@ -90,21 +82,12 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
} }
$scope.realm = angular.copy(realm); $scope.realm = angular.copy(realm);
$scope.realm.requireSsl = !realm.sslNotRequired; $scope.realm.requireSsl = !realm.sslNotRequired;
$scope.realm.tokenLifespanUnit = 'SECONDS';
$scope.realm.accessCodeLifespanUnit = 'SECONDS';
} }
var oldCopy = angular.copy($scope.realm); var oldCopy = angular.copy($scope.realm);
$scope.userCredentialOptions = {
'multiple' : true,
'simple_tags' : true,
'tags' : ['password', 'totp', 'cert']
};
$scope.changed = $scope.create; $scope.changed = $scope.create;
$scope.$watch('realm', function() { $scope.$watch('realm', function() {
@ -118,8 +101,6 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
var realmCopy = angular.copy($scope.realm); var realmCopy = angular.copy($scope.realm);
realmCopy.sslNotRequired = !realmCopy.requireSsl; realmCopy.sslNotRequired = !realmCopy.requireSsl;
delete realmCopy["requireSsl"]; delete realmCopy["requireSsl"];
delete realmCopy["tokenLifespanUnit"];
delete realmCopy["accessCodeLifespanUnit"];
if ($scope.createRealm) { if ($scope.createRealm) {
Realm.save(realmCopy, function(data, headers) { Realm.save(realmCopy, function(data, headers) {
console.log('creating new realm'); console.log('creating new realm');
@ -180,6 +161,105 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
}; };
}); });
module.controller('RealmRequiredCredentialsCtrl', function($scope, Realm, realm, $http, $location, Dialog, Notifications) {
console.log('RealmRequiredCredentialsCtrl');
$scope.realm = {
id : realm.id, realm : realm.realm,
requiredCredentials : realm.requiredCredentials,
requiredApplicationCredentials : realm.requiredApplicationCredentials,
requiredOAuthClientCredentials : realm.requiredOAuthClientCredentials
};
$scope.userCredentialOptions = {
'multiple' : true,
'simple_tags' : true,
'tags' : ['password', 'totp', 'cert']
};
var oldCopy = angular.copy($scope.realm);
$scope.changed = false;
$scope.$watch('realm', function() {
if (!angular.equals($scope.realm, oldCopy)) {
$scope.changed = true;
}
}, true);
$scope.save = function() {
if ($scope.realmForm.$valid) {
var realmCopy = angular.copy($scope.realm);
$scope.changed = false;
Realm.update(realmCopy, function () {
$location.url("/realms/" + realm.id + "/required-credentials");
Notifications.success("Saved changes to realm");
});
} else {
$scope.realmForm.showErrors = true;
}
};
$scope.reset = function() {
$scope.realm = angular.copy(oldCopy);
$scope.changed = false;
$scope.realmForm.showErrors = false;
};
});
module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http, $location, Dialog, Notifications) {
console.log('RealmTokenDetailCtrl');
$scope.realm = { id : realm.id, realm : realm.realm, tokenLifespan : realm.tokenLifespan, accessCodeLifespan : realm.accessCodeLifespan };
$scope.realm.tokenLifespanUnit = 'Seconds';
$scope.realm.accessCodeLifespanUnit = 'Seconds';
var oldCopy = angular.copy($scope.realm);
$scope.changed = false;
$scope.$watch('realm', function() {
if (!angular.equals($scope.realm, oldCopy)) {
$scope.changed = true;
}
}, true);
$scope.save = function() {
if ($scope.realmForm.$valid) {
var realmCopy = angular.copy($scope.realm);
delete realmCopy["tokenLifespanUnit"];
delete realmCopy["accessCodeLifespanUnit"];
if ($scope.realm.tokenLifespanUnit == 'Minutes') {
realmCopy.tokenLifespan = $scope.realm.tokenLifespan * 60;
} else if ($scope.realm.tokenLifespanUnit == 'Hours') {
realmCopy.tokenLifespan = $scope.realm.tokenLifespan * 60 * 60;
} else if ($scope.realm.tokenLifespanUnit == 'Days') {
realmCopy.tokenLifespan = $scope.realm.tokenLifespan * 60 * 60 * 24;
}
if ($scope.realm.accessCodeLifespanUnit == 'Minutes') {
realmCopy.accessCodeLifespan = $scope.realm.accessCodeLifespan * 60;
} else if ($scope.realm.accessCodeLifespanUnit == 'Hours') {
realmCopy.accessCodeLifespan = $scope.realm.accessCodeLifespan * 60 * 60;
} else if ($scope.realm.accessCodeLifespanUnit == 'Days') {
realmCopy.accessCodeLifespan = $scope.realm.accessCodeLifespan * 60 * 60 * 24;
}
$scope.changed = false;
Realm.update(realmCopy, function () {
$location.url("/realms/" + realm.id + "/token-settings");
Notifications.success("Saved changes to realm");
});
} else {
$scope.realmForm.showErrors = true;
}
};
$scope.reset = function() {
$scope.realm = angular.copy(oldCopy);
$scope.changed = false;
$scope.realmForm.showErrors = false;
};
});
module.controller('UserListCtrl', function($scope, realm, User) { module.controller('UserListCtrl', function($scope, realm, User) {
$scope.realm = realm; $scope.realm = realm;

View file

@ -4,18 +4,19 @@
<div id="content-area" class="col-md-9" role="main"> <div id="content-area" class="col-md-9" role="main">
<div class="top-nav" data-ng-hide="createRealm"> <div class="top-nav" data-ng-hide="createRealm">
<ul class="rcue-tabs"> <ul class="rcue-tabs">
<li><a href="#">Settings</a></li> <li><a href="#/realms/{{realm.id}}">Settings</a></li>
<li data-ng-show="realm.social"><a href="#">Social</a></li> <li data-ng-show="realm.social"><a href="#">Social</a></li>
<li><a href="#">Roles</a></li> <li><a href="#/realms/{{realm.id}}/roles">Roles</a></li>
<li class="active"><a href="#">Required Credentials</a></li> <li class="active"><a href="#/realms/{{realm.id}}/required-credentials">Required Credentials</a></li>
<li><a href="#">Token Settings</a></li> <li><a href="#/realms/{{realm.id}}/token-settings">Token Settings</a></li>
</ul> </ul>
</div> </div>
<div id="content"> <div id="content">
<h2 class="pull-left">Realm: <span>{{realm.realm}}</span></h2> <h2 class="pull-left">Realm: <span>{{realm.realm}}</span></h2>
<p class="subtitle"></p>
<form name="realmForm" novalidate> <form name="realmForm" novalidate>
<fieldset> <fieldset>
<legend collapsed><span class="text">Required Credentials</span></legend> <legend uncollapsed><span class="text">Required Credentials</span></legend>
<div class="form-group"> <div class="form-group">
<label class="control-label">Required User Credentials</label> <label class="control-label">Required User Credentials</label>

View file

@ -7,8 +7,8 @@
<li class="active"><a href="#/realms/{{realm.id}}">Settings</a></li> <li class="active"><a href="#/realms/{{realm.id}}">Settings</a></li>
<li data-ng-show="realm.social"><a href="#">Social</a></li> <li data-ng-show="realm.social"><a href="#">Social</a></li>
<li><a href="#/realms/{{realm.id}}/roles">Roles</a></li> <li><a href="#/realms/{{realm.id}}/roles">Roles</a></li>
<li><a href="#">Required Credentials</a></li> <li><a href="#/realms/{{realm.id}}/required-credentials">Required Credentials</a></li>
<li><a href="#">Token Settings</a></li> <li><a href="#/realms/{{realm.id}}/token-settings">Token Settings</a></li>
</ul> </ul>
</div> </div>
<div id="content"> <div id="content">
@ -97,61 +97,6 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<legend collapsed><span class="text">Token Settings</span></legend>
<div class="form-group input-select">
<label for="tokenLifespan">Token lifespan</label>
<div class="input-group">
<input type="text" data-ng-model="realm.tokenLifespan" id="tokenLifespan" name="tokenLifespan" class="tiny">
<div class="select-rcue">
<select name="tokenLifespanUnit" data-ng-model="realm.tokenLifespanUnit">
<option data-ng-selected="!realm.tokenLifespanUnit">Seconds</option>
<option>Minutes</option>
<option>Hours</option>
<option>Days</option>
</select>
</div>
</div>
</div>
<div class="form-group input-select">
<label for="accessCodeLifespan">Access code lifespan</label>
<div class="input-group">
<input type="text" data-ng-model="realm.accessCodeLifespan" id="accessCodeLifespan" name="accessCodeLifespan" class="tiny">
<div class="select-rcue">
<select name="accessCodeLifespanUnit" data-ng-model="realm.accessCodeLifespanUnit">
<option data-ng-selected="!realm.accessCodeLifespanUnit">Seconds</option>
<option>Minutes</option>
<option>Hours</option>
<option>Days</option>
</select>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend collapsed><span class="text">Default Credential Settings</span></legend>
<div class="form-group">
<label class="control-label">Required User Credentials</label>
<div class="controls">
<input style="width:250px" type="text" ui-select2="userCredentialOptions" ng-model="realm.requiredCredentials">
</div>
</div>
<div class="form-group">
<label class="control-label">Required Application Credentials</label>
<div class="controls">
<input style="width:250;height:25" type="text" ui-select2="userCredentialOptions" ng-model="realm.requiredApplicationCredentials">
</div>
</div>
<div class="form-group">
<label class="control-label">Required OAuth Credentials</label>
<div class="controls">
<input style="width:250px" type="text" ui-select2="userCredentialOptions" ng-model="realm.requiredOAuthClientCredentials">
</div>
</div>
</fieldset>
<div class="form-actions" data-ng-show="createRealm"> <div class="form-actions" data-ng-show="createRealm">
<button type="submit" data-ng-click="save()" class="primary" data-ng-show="changed">Save <button type="submit" data-ng-click="save()" class="primary" data-ng-show="changed">Save
</button> </button>

View file

@ -1,5 +1,5 @@
<ul data-ng-hide="createRealm"> <ul data-ng-hide="createRealm">
<li data-ng-class="(!path[2] || path[1] == 'role' || path[2] == 'roles') && 'active'"><a href="#/realms/{{realm.id}}">Realm Settings</a></li> <li data-ng-class="(!path[2] || path[1] == 'role' || path[2] == 'roles' || path[2] == 'token-settings' || path[2] == 'required-credentials') && 'active'"><a href="#/realms/{{realm.id}}">Realm Settings</a></li>
<li data-ng-class="(path[2] == 'users' || path[1] == 'user') && 'active'"><a href="#/realms/{{realm.id}}/users">Users</a> <li data-ng-class="(path[2] == 'users' || path[1] == 'user') && 'active'"><a href="#/realms/{{realm.id}}/users">Users</a>
</li> </li>
<li data-ng-class="(path[2] == 'applications' || path[1] == 'application') && 'active'"><a href="#/realms/{{realm.id}}/applications">Applications</a></li> <li data-ng-class="(path[2] == 'applications' || path[1] == 'application') && 'active'"><a href="#/realms/{{realm.id}}/applications">Applications</a></li>

View file

@ -4,18 +4,19 @@
<div id="content-area" class="col-md-9" role="main"> <div id="content-area" class="col-md-9" role="main">
<div class="top-nav" data-ng-hide="createRealm"> <div class="top-nav" data-ng-hide="createRealm">
<ul class="rcue-tabs"> <ul class="rcue-tabs">
<li><a href="#">Settings</a></li> <li><a href="#/realms/{{realm.id}}">Settings</a></li>
<li data-ng-show="realm.social"><a href="#">Social</a></li> <li data-ng-show="realm.social"><a href="#">Social</a></li>
<li><a href="#">Roles</a></li> <li><a href="#/realms/{{realm.id}}/roles">Roles</a></li>
<li><a href="#">Required Credentials</a></li> <li><a href="#/realms/{{realm.id}}/required-credentials">Required Credentials</a></li>
<li class="active"><a href="#">Token Settings</a></li> <li class="active"><a href="#/realms/{{realm.id}}/token-settings">Token Settings</a></li>
</ul> </ul>
</div> </div>
<div id="content"> <div id="content">
<h2 class="pull-left">Realm: <span>{{realm.realm}}</span></h2> <h2 class="pull-left">Realm: <span>{{realm.realm}}</span></h2>
<p class="subtitle"></p>
<form name="realmForm" novalidate> <form name="realmForm" novalidate>
<fieldset> <fieldset>
<legend collapsed><span class="text">Token Settings</span></legend> <legend uncollapsed><span class="text">Token Settings</span></legend>
<div class="form-group input-select"> <div class="form-group input-select">
<label for="tokenLifespan">Token lifespan</label> <label for="tokenLifespan">Token lifespan</label>
<div class="input-group"> <div class="input-group">

View file

@ -68,17 +68,17 @@ public class RealmManager {
public void updateRealm(RealmRepresentation rep, RealmModel realm) { public void updateRealm(RealmRepresentation rep, RealmModel realm) {
if (rep.getRealm() != null) realm.setName(rep.getRealm()); if (rep.getRealm() != null) realm.setName(rep.getRealm());
realm.setEnabled(rep.isEnabled()); if (rep.isEnabled() != null) realm.setEnabled(rep.isEnabled());
realm.setSocial(rep.isSocial()); if (rep.isSocial() != null) realm.setSocial(rep.isSocial());
realm.setCookieLoginAllowed(rep.isCookieLoginAllowed()); if (rep.isCookieLoginAllowed() != null) realm.setCookieLoginAllowed(rep.isCookieLoginAllowed());
realm.setRegistrationAllowed(rep.isRegistrationAllowed()); if (rep.isRegistrationAllowed() != null) realm.setRegistrationAllowed(rep.isRegistrationAllowed());
realm.setVerifyEmail(rep.isVerifyEmail()); if (rep.isVerifyEmail() != null) realm.setVerifyEmail(rep.isVerifyEmail());
realm.setResetPasswordAllowed(rep.isResetPasswordAllowed()); if (rep.isResetPasswordAllowed() != null) realm.setResetPasswordAllowed(rep.isResetPasswordAllowed());
realm.setAutomaticRegistrationAfterSocialLogin(rep.isAutomaticRegistrationAfterSocialLogin()); if (rep.isAutomaticRegistrationAfterSocialLogin() != null) realm.setAutomaticRegistrationAfterSocialLogin(rep.isAutomaticRegistrationAfterSocialLogin());
realm.setSslNotRequired((rep.isSslNotRequired())); if (rep.isSslNotRequired() != null) realm.setSslNotRequired((rep.isSslNotRequired()));
realm.setAccessCodeLifespan(rep.getAccessCodeLifespan()); if (rep.getAccessCodeLifespan() != null) realm.setAccessCodeLifespan(rep.getAccessCodeLifespan());
realm.setAccessCodeLifespanUserAction(rep.getAccessCodeLifespanUserAction()); if (rep.getAccessCodeLifespanUserAction() != null) realm.setAccessCodeLifespanUserAction(rep.getAccessCodeLifespanUserAction());
realm.setTokenLifespan(rep.getTokenLifespan()); if (rep.getTokenLifespan() != null) realm.setTokenLifespan(rep.getTokenLifespan());
if (rep.getRequiredOAuthClientCredentials() != null) { if (rep.getRequiredOAuthClientCredentials() != null) {
realm.updateRequiredOAuthClientCredentials(rep.getRequiredOAuthClientCredentials()); realm.updateRequiredOAuthClientCredentials(rep.getRequiredOAuthClientCredentials());
} }
@ -104,17 +104,24 @@ public class RealmManager {
public void importRealm(RealmRepresentation rep, RealmModel newRealm) { public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
newRealm.setName(rep.getRealm()); newRealm.setName(rep.getRealm());
newRealm.setEnabled(rep.isEnabled()); if (rep.isEnabled() != null) newRealm.setEnabled(rep.isEnabled());
newRealm.setSocial(rep.isSocial()); if (rep.isSocial() != null) newRealm.setSocial(rep.isSocial());
newRealm.setTokenLifespan(rep.getTokenLifespan());
newRealm.setAccessCodeLifespan(rep.getAccessCodeLifespan()); if (rep.getTokenLifespan() != null) newRealm.setTokenLifespan(rep.getTokenLifespan());
newRealm.setAccessCodeLifespanUserAction(rep.getAccessCodeLifespanUserAction()); else newRealm.setTokenLifespan(300);
newRealm.setSslNotRequired(rep.isSslNotRequired());
newRealm.setCookieLoginAllowed(rep.isCookieLoginAllowed()); if (rep.getAccessCodeLifespan() != null) newRealm.setAccessCodeLifespan(rep.getAccessCodeLifespan());
newRealm.setRegistrationAllowed(rep.isRegistrationAllowed()); else newRealm.setAccessCodeLifespan(60);
newRealm.setVerifyEmail(rep.isVerifyEmail());
newRealm.setResetPasswordAllowed(rep.isResetPasswordAllowed()); if (rep.getAccessCodeLifespanUserAction() != null) newRealm.setAccessCodeLifespanUserAction(rep.getAccessCodeLifespanUserAction());
newRealm.setAutomaticRegistrationAfterSocialLogin(rep.isAutomaticRegistrationAfterSocialLogin()); else newRealm.setAccessCodeLifespanUserAction(300);
if (rep.isSslNotRequired() != null) newRealm.setSslNotRequired(rep.isSslNotRequired());
if (rep.isCookieLoginAllowed() != null) newRealm.setCookieLoginAllowed(rep.isCookieLoginAllowed());
if (rep.isRegistrationAllowed() != null) newRealm.setRegistrationAllowed(rep.isRegistrationAllowed());
if (rep.isVerifyEmail() != null) newRealm.setVerifyEmail(rep.isVerifyEmail());
if (rep.isResetPasswordAllowed() != null) newRealm.setResetPasswordAllowed(rep.isResetPasswordAllowed());
if (rep.isAutomaticRegistrationAfterSocialLogin() != null) newRealm.setAutomaticRegistrationAfterSocialLogin(rep.isAutomaticRegistrationAfterSocialLogin());
if (rep.getPrivateKey() == null || rep.getPublicKey() == null) { if (rep.getPrivateKey() == null || rep.getPublicKey() == null) {
generateRealmKeys(newRealm); generateRealmKeys(newRealm);
} else { } else {
@ -128,18 +135,24 @@ public class RealmManager {
for (String requiredCred : rep.getRequiredCredentials()) { for (String requiredCred : rep.getRequiredCredentials()) {
addRequiredCredential(newRealm, requiredCred); addRequiredCredential(newRealm, requiredCred);
} }
} else {
addRequiredCredential(newRealm, CredentialRepresentation.PASSWORD);
} }
if (rep.getRequiredApplicationCredentials() != null) { if (rep.getRequiredApplicationCredentials() != null) {
for (String requiredCred : rep.getRequiredApplicationCredentials()) { for (String requiredCred : rep.getRequiredApplicationCredentials()) {
addResourceRequiredCredential(newRealm, requiredCred); addResourceRequiredCredential(newRealm, requiredCred);
} }
} else {
addResourceRequiredCredential(newRealm, CredentialRepresentation.PASSWORD);
} }
if (rep.getRequiredOAuthClientCredentials() != null) { if (rep.getRequiredOAuthClientCredentials() != null) {
for (String requiredCred : rep.getRequiredOAuthClientCredentials()) { for (String requiredCred : rep.getRequiredOAuthClientCredentials()) {
addOAuthClientRequiredCredential(newRealm, requiredCred); addOAuthClientRequiredCredential(newRealm, requiredCred);
} }
} else {
addOAuthClientRequiredCredential(newRealm, CredentialRepresentation.PASSWORD);
} }
if (rep.getUsers() != null) { if (rep.getUsers() != null) {

View file

@ -59,7 +59,7 @@ public class RealmAdminResource {
@PUT @PUT
@Consumes("application/json") @Consumes("application/json")
public void updateRealm(final RealmRepresentation rep) { public void updateRealm(final RealmRepresentation rep) {
logger.info("updating realm: " + rep.getRealm()); logger.info("updating realm: " + realm.getName());
new RealmManager(session).updateRealm(rep, realm); new RealmManager(session).updateRealm(rep, realm);
} }

View file

@ -9,7 +9,6 @@ import org.keycloak.services.models.*;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.container.ResourceContext; import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
@ -150,11 +149,11 @@ public class UsersResource {
List<ApplicationModel> applications = realm.getApplications(); List<ApplicationModel> applications = realm.getApplications();
if (applications.size() > 0) { if (applications.size() > 0) {
Map<String, ApplicationRoleMappings> appMappings = new HashMap<String, ApplicationRoleMappings>(); Map<String, ApplicationRoleMappingsRepresentation> appMappings = new HashMap<String, ApplicationRoleMappingsRepresentation>();
for (ApplicationModel application : applications) { for (ApplicationModel application : applications) {
List<RoleModel> roleMappings = application.getRoleMappings(user); List<RoleModel> roleMappings = application.getRoleMappings(user);
if (roleMappings.size() > 0) { if (roleMappings.size() > 0) {
ApplicationRoleMappings mappings = new ApplicationRoleMappings(); ApplicationRoleMappingsRepresentation mappings = new ApplicationRoleMappingsRepresentation();
mappings.setUsername(user.getLoginName()); mappings.setUsername(user.getLoginName());
mappings.setApplicationId(application.getId()); mappings.setApplicationId(application.getId());
mappings.setApplication(application.getName()); mappings.setApplication(application.getName());
@ -257,7 +256,6 @@ public class UsersResource {
throw new NotFoundException(); throw new NotFoundException();
} }
ApplicationRoleMappings rep = new ApplicationRoleMappings();
List<RoleModel> mappings = application.getRoleMappings(user); List<RoleModel> mappings = application.getRoleMappings(user);
List<RoleRepresentation> mapRep = new ArrayList<RoleRepresentation>(); List<RoleRepresentation> mapRep = new ArrayList<RoleRepresentation>();
for (RoleModel roleModel : mappings) { for (RoleModel roleModel : mappings) {