realm name for url param
This commit is contained in:
parent
4825974edc
commit
2dbd7cfa02
6 changed files with 47 additions and 32 deletions
|
@ -24,15 +24,15 @@ module.controller('HomeCtrl', function(Realm, $location) {
|
|||
Realm.query(null, function(realms) {
|
||||
var realm;
|
||||
if (realms.length == 1) {
|
||||
realm = realms[0].id;
|
||||
realm = realms[0].realm;
|
||||
} else if (realms.length == 2) {
|
||||
if (realms[0].realm == 'Keycloak Administration') {
|
||||
realm = realms[1].id;
|
||||
realm = realms[1].realm;
|
||||
} else if (realms[1].realm == 'Keycloak Administration') {
|
||||
realm = realms[0].id;
|
||||
realm = realms[0].realm;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("****** HomeCtrl ******");
|
||||
if (realm) {
|
||||
$location.url('/realms/' + realm);
|
||||
} else {
|
||||
|
@ -118,18 +118,16 @@ module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $
|
|||
|
||||
$scope.save = function() {
|
||||
var realmCopy = angular.copy($scope.realm);
|
||||
Realm.save(realmCopy, function(data, headers) {
|
||||
console.log('creating new realm');
|
||||
var l = headers().location;
|
||||
var id = l.substring(l.lastIndexOf("/") + 1);
|
||||
console.log('creating new realm **');
|
||||
Realm.create(realmCopy, function(data, headers) {
|
||||
var data = Realm.query(function() {
|
||||
Current.realms = data;
|
||||
for (var i = 0; i < Current.realms.length; i++) {
|
||||
if (Current.realms[i].id == id) {
|
||||
if (Current.realms[i].realm == realmCopy.realm) {
|
||||
Current.realm = Current.realms[i];
|
||||
}
|
||||
}
|
||||
$location.url("/realms/" + id);
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
Notifications.success("The realm has been created.");
|
||||
});
|
||||
});
|
||||
|
@ -156,17 +154,26 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
|
|||
} else {
|
||||
if (Current.realm == null || Current.realm.realm != realm.realm) {
|
||||
for (var i = 0; i < Current.realms.length; i++) {
|
||||
if (realm.realm == Current.realms[i].id) {
|
||||
if (realm.realm == Current.realms[i].realm) {
|
||||
Current.realm = Current.realms[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('realm name: ' + realm.realm);
|
||||
for (var i = 0; i < Current.realms.length; i++) {
|
||||
console.log('checking Current.realm:' + Current.realms[i].realm);
|
||||
if (Current.realms[i].realm == realm.realm) {
|
||||
Current.realm = Current.realms[i];
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (Current.realm == null || Current.realm.realm != realm.realm) {
|
||||
console.log('should be unreachable');
|
||||
console.log('Why? ' + Current.realms.length + ' ' + Current.realm);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
$scope.realm = angular.copy(realm);
|
||||
$scope.realm.requireSsl = !realm.sslNotRequired;
|
||||
}
|
||||
|
@ -193,16 +200,14 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
|
|||
if ($scope.createRealm) {
|
||||
Realm.save(realmCopy, function(data, headers) {
|
||||
console.log('creating new realm');
|
||||
var l = headers().location;
|
||||
var id = l.substring(l.lastIndexOf("/") + 1);
|
||||
var data = Realm.query(function() {
|
||||
Current.realms = data;
|
||||
for (var i = 0; i < Current.realms.length; i++) {
|
||||
if (Current.realms[i].id == id) {
|
||||
if (Current.realms[i].realm == realmCopy.realm) {
|
||||
Current.realm = Current.realms[i];
|
||||
}
|
||||
}
|
||||
$location.url("/realms/" + id);
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
Notifications.success("The realm has been created.");
|
||||
$scope.social = $scope.realm.social;
|
||||
$scope.registrationAllowed = $scope.realm.registrationAllowed;
|
||||
|
@ -211,18 +216,18 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
|
|||
} else {
|
||||
console.log('updating realm...');
|
||||
$scope.changed = false;
|
||||
Realm.update(realmCopy, function () {
|
||||
var id = realmCopy.id;
|
||||
console.log('oldCopy.realm - ' + oldCopy.realm);
|
||||
Realm.update({ id : oldCopy.realm}, realmCopy, function () {
|
||||
var data = Realm.query(function () {
|
||||
Current.realms = data;
|
||||
for (var i = 0; i < Current.realms.length; i++) {
|
||||
if (Current.realms[i].id == id) {
|
||||
if (Current.realms[i].realm == realmCopy.realm) {
|
||||
Current.realm = Current.realms[i];
|
||||
oldCopy = angular.copy($scope.realm);
|
||||
}
|
||||
}
|
||||
});
|
||||
$location.url("/realms/" + id);
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
Notifications.success("Your changes have been saved to the realm.");
|
||||
$scope.social = $scope.realm.social;
|
||||
$scope.registrationAllowed = $scope.realm.registrationAllowed;
|
||||
|
|
|
@ -107,12 +107,17 @@ module.factory('Notifications', function($rootScope, $timeout) {
|
|||
|
||||
module.factory('Realm', function($resource) {
|
||||
return $resource('/auth/rest/admin/realms/:id', {
|
||||
id : '@id'
|
||||
id : '@realm'
|
||||
}, {
|
||||
update : {
|
||||
method : 'PUT'
|
||||
}
|
||||
});
|
||||
},
|
||||
create : {
|
||||
method : 'POST',
|
||||
params : { id : ''}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
module.factory('User', function($resource) {
|
||||
|
@ -120,9 +125,9 @@ module.factory('User', function($resource) {
|
|||
realm : '@realm',
|
||||
userId : '@userId'
|
||||
}, {
|
||||
update : {
|
||||
method : 'PUT'
|
||||
}
|
||||
update : {
|
||||
method : 'PUT'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -321,7 +326,7 @@ module.factory('Current', function(Realm, $route) {
|
|||
current.realms = Realm.query(null, function(realms) {
|
||||
if ($route.current.params.realm) {
|
||||
for (var i = 0; i < realms.length; i++) {
|
||||
if (realms[i].id == $route.current.params.realm) {
|
||||
if (realms[i].realm == $route.current.params.realm) {
|
||||
current.realm = realms[i];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tr data-ng-repeat="r in realms">
|
||||
<td><a href="#/realms/{{r.id}}">{{r.realm}}</a></td>
|
||||
<td><a href="#/realms/{{r.realm}}">{{r.realm}}</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -63,7 +63,10 @@ public class JpaKeycloakSession implements KeycloakSession {
|
|||
public RealmModel getRealmByName(String name) {
|
||||
TypedQuery<RealmEntity> query = em.createNamedQuery("getRealmByName", RealmEntity.class);
|
||||
query.setParameter("name", name);
|
||||
RealmEntity realm = query.getSingleResult();
|
||||
List<RealmEntity> entities = query.getResultList();
|
||||
if (entities.size() == 0) return null;
|
||||
if (entities.size() > 1) throw new IllegalStateException("Should not be more than one realm with same name");
|
||||
RealmEntity realm = query.getResultList().get(0);
|
||||
if (realm == null) return null;
|
||||
return new RealmAdapter(em, realm);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class RealmManager {
|
|||
}
|
||||
|
||||
public RealmModel getRealmByName(String name) {
|
||||
return identitySession.getRealm(name);
|
||||
return identitySession.getRealmByName(name);
|
||||
}
|
||||
|
||||
public RealmModel createRealm(String name) {
|
||||
|
@ -93,7 +93,10 @@ public class RealmManager {
|
|||
}
|
||||
|
||||
public void updateRealm(RealmRepresentation rep, RealmModel realm) {
|
||||
if (rep.getRealm() != null) realm.setName(rep.getRealm());
|
||||
if (rep.getRealm() != null) {
|
||||
logger.info("Updating realm name to " + rep.getRealm());
|
||||
realm.setName(rep.getRealm());
|
||||
}
|
||||
if (rep.isEnabled() != null) realm.setEnabled(rep.isEnabled());
|
||||
if (rep.isSocial() != null) realm.setSocial(rep.isSocial());
|
||||
if (rep.isCookieLoginAllowed() != null) realm.setCookieLoginAllowed(rep.isCookieLoginAllowed());
|
||||
|
@ -169,7 +172,6 @@ public class RealmManager {
|
|||
}
|
||||
|
||||
public RealmModel importRealm(RealmRepresentation rep, UserModel realmCreator) {
|
||||
//verifyRealmRepresentation(rep);
|
||||
RealmModel realm = createRealm(rep.getRealm());
|
||||
importRealm(rep, realm);
|
||||
return realm;
|
||||
|
|
|
@ -107,7 +107,7 @@ public class RealmsAdminResource {
|
|||
@PathParam("realm") final String name) {
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
RealmModel realm = realmManager.getRealmByName(name);
|
||||
if (realm == null) throw new NotFoundException();
|
||||
if (realm == null) throw new NotFoundException("{realm} = " + name);
|
||||
|
||||
RealmAdminResource adminResource = new RealmAdminResource(admin, realm);
|
||||
resourceContext.initResource(adminResource);
|
||||
|
|
Loading…
Reference in a new issue