role name instead of id

This commit is contained in:
Bill Burke 2014-01-15 19:39:21 -05:00
parent ed0d33126c
commit 894c28c64f
13 changed files with 37 additions and 33 deletions

View file

@ -137,7 +137,7 @@ module.controller('ApplicationRoleDetailCtrl', function($scope, realm, applicati
ApplicationRole.update({ ApplicationRole.update({
realm : realm.realm, realm : realm.realm,
application : application.name, application : application.name,
roleId : role.id role : role.name
}, $scope.role, function() { }, $scope.role, function() {
$scope.changed = false; $scope.changed = false;
role = angular.copy($scope.role); role = angular.copy($scope.role);
@ -160,7 +160,7 @@ module.controller('ApplicationRoleDetailCtrl', function($scope, realm, applicati
$scope.role.$remove({ $scope.role.$remove({
realm : realm.realm, realm : realm.realm,
application : application.name, application : application.name,
roleId : $scope.role.id role : $scope.role.name
}, function() { }, function() {
$location.url("/realms/" + realm.realm + "/applications/" + application.name + "/roles"); $location.url("/realms/" + realm.realm + "/applications/" + application.name + "/roles");
Notifications.success("The role has been deleted."); Notifications.success("The role has been deleted.");

View file

@ -818,7 +818,7 @@ module.controller('RoleDetailCtrl', function($scope, realm, role, Role, $locatio
} else { } else {
Role.update({ Role.update({
realm : realm.realm, realm : realm.realm,
roleId : role.id role : role.name
}, $scope.role, function() { }, $scope.role, function() {
$scope.changed = false; $scope.changed = false;
role = angular.copy($scope.role); role = angular.copy($scope.role);
@ -840,7 +840,7 @@ module.controller('RoleDetailCtrl', function($scope, realm, role, Role, $locatio
Dialog.confirmDelete($scope.role.name, 'role', function() { Dialog.confirmDelete($scope.role.name, 'role', function() {
$scope.role.$remove({ $scope.role.$remove({
realm : realm.realm, realm : realm.realm,
roleId : $scope.role.id role : $scope.role.name
}, function() { }, function() {
$location.url("/realms/" + realm.realm + "/roles"); $location.url("/realms/" + realm.realm + "/roles");
Notifications.success("The role has been deleted."); Notifications.success("The role has been deleted.");

View file

@ -64,7 +64,7 @@ module.factory('RoleLoader', function(Loader, Role, $route, $q) {
return Loader.get(Role, function() { return Loader.get(Role, function() {
return { return {
realm : $route.current.params.realm, realm : $route.current.params.realm,
roleId : $route.current.params.role role : $route.current.params.role
} }
}); });
}); });
@ -82,7 +82,7 @@ module.factory('ApplicationRoleLoader', function(Loader, ApplicationRole, $route
return { return {
realm : $route.current.params.realm, realm : $route.current.params.realm,
application : $route.current.params.application, application : $route.current.params.application,
roleId : $route.current.params.role role : $route.current.params.role
} }
}); });
}); });

View file

@ -184,9 +184,9 @@ module.factory('RealmRoles', function($resource) {
module.factory('Role', function($resource) { module.factory('Role', function($resource) {
return $resource('/auth/rest/admin/realms/:realm/roles/:roleId', { return $resource('/auth/rest/admin/realms/:realm/roles/:role', {
realm : '@realm', realm : '@realm',
roleId : '@roleId' role : '@role'
}, { }, {
update : { update : {
method : 'PUT' method : 'PUT'
@ -195,10 +195,10 @@ module.factory('Role', function($resource) {
}); });
module.factory('ApplicationRole', function($resource) { module.factory('ApplicationRole', function($resource) {
return $resource('/auth/rest/admin/realms/:realm/applications/:application/roles/:roleId', { return $resource('/auth/rest/admin/realms/:realm/applications/:application/roles/:role', {
realm : '@realm', realm : '@realm',
application : "@application", application : "@application",
roleId : '@roleId' role : '@role'
}, { }, {
update : { update : {
method : 'PUT' method : 'PUT'

View file

@ -64,7 +64,7 @@
</tfoot> </tfoot>
<tbody> <tbody>
<tr ng-repeat="role in roles"> <tr ng-repeat="role in roles">
<td><a href="#/realms/{{realm.realm}}/applications/{{application.name}}/roles/{{role.id}}">{{role.name}}</a></td> <td><a href="#/realms/{{realm.realm}}/applications/{{application.name}}/roles/{{role.name}}">{{role.name}}</a></td>
<td>{{role.description}}</td> <td>{{role.description}}</td>
</tr> </tr>
</tbody> </tbody>

View file

@ -64,7 +64,7 @@
</tfoot> </tfoot>
<tbody> <tbody>
<tr ng-repeat="role in roles"> <tr ng-repeat="role in roles">
<td><a href="#/realms/{{realm.realm}}/roles/{{role.id}}">{{role.name}}</a></td> <td><a href="#/realms/{{realm.realm}}/roles/{{role.name}}">{{role.name}}</a></td>
<td>{{role.description}}</td> <td>{{role.description}}</td>
</tr> </tr>
</tbody> </tbody>

View file

@ -11,7 +11,7 @@ public interface RoleContainerModel {
RoleModel addRole(String name); RoleModel addRole(String name);
boolean removeRole(String id); boolean removeRoleById(String id);
List<RoleModel> getRoles(); List<RoleModel> getRoles();

View file

@ -117,7 +117,7 @@ public class ApplicationAdapter implements ApplicationModel {
} }
@Override @Override
public boolean removeRole(String id) { public boolean removeRoleById(String id) {
RoleEntity role = em.find(RoleEntity.class, id); RoleEntity role = em.find(RoleEntity.class, id);
if (role == null) { if (role == null) {
return false; return false;

View file

@ -841,7 +841,7 @@ public class RealmAdapter implements RealmModel {
} }
@Override @Override
public boolean removeRole(String id) { public boolean removeRoleById(String id) {
RoleEntity role = em.find(RoleEntity.class, id); RoleEntity role = em.find(RoleEntity.class, id);
if (role == null) { if (role == null) {
return false; return false;

View file

@ -156,7 +156,7 @@ public class ApplicationAdapter implements ApplicationModel {
} }
@Override @Override
public boolean removeRole(String id) { public boolean removeRoleById(String id) {
try { try {
getIdm().remove(getIdm().lookupIdentityById(Role.class, id)); getIdm().remove(getIdm().lookupIdentityById(Role.class, id));
return true; return true;

View file

@ -564,7 +564,7 @@ public class RealmAdapter implements RealmModel {
} }
@Override @Override
public boolean removeRole(String id) { public boolean removeRoleById(String id) {
try { try {
getIdm().remove(getIdm().lookupIdentityById(Role.class, id)); getIdm().remove(getIdm().lookupIdentityById(Role.class, id));
return true; return true;

View file

@ -42,36 +42,40 @@ public class RoleContainerResource {
return roles; return roles;
} }
@Path("roles/{id}") @Path("roles/{role-name}")
@GET @GET
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
public RoleRepresentation getRole(final @PathParam("id") String id) { public RoleRepresentation getRole(final @PathParam("role-name") String roleName) {
RoleModel roleModel = roleContainer.getRoleById(id); RoleModel roleModel = roleContainer.getRole(roleName);
if (roleModel == null || roleModel.getName().startsWith(Constants.INTERNAL_ROLE)) { if (roleModel == null || roleModel.getName().startsWith(Constants.INTERNAL_ROLE)) {
throw new NotFoundException(); throw new NotFoundException("Could not find role: " + roleName);
} }
RoleRepresentation rep = new RoleRepresentation(roleModel.getName(), roleModel.getDescription()); RoleRepresentation rep = new RoleRepresentation(roleModel.getName(), roleModel.getDescription());
rep.setId(roleModel.getId()); rep.setId(roleModel.getId());
return rep; return rep;
} }
@Path("roles/{id}") @Path("roles/{role-name}")
@DELETE @DELETE
@NoCache @NoCache
public void deleteRole(final @PathParam("id") String id) { public void deleteRole(final @PathParam("role-name") String roleName) {
if (!roleContainer.removeRole(id)) { RoleModel role = roleContainer.getRole(roleName);
if (role == null) {
throw new NotFoundException("Could not find role: " + roleName);
}
if (!roleContainer.removeRoleById(role.getId())) {
throw new NotFoundException(); throw new NotFoundException();
} }
} }
@Path("roles/{id}") @Path("roles/{role-name}")
@PUT @PUT
@Consumes("application/json") @Consumes("application/json")
public void updateRole(final @PathParam("id") String id, final RoleRepresentation rep) { public void updateRole(final @PathParam("role-name") String roleName, final RoleRepresentation rep) {
RoleModel role = roleContainer.getRoleById(id); RoleModel role = roleContainer.getRole(roleName);
if (role == null || role.getName().startsWith(Constants.INTERNAL_ROLE)) { if (role == null || role.getName().startsWith(Constants.INTERNAL_ROLE)) {
throw new NotFoundException(); throw new NotFoundException("Could not find role: " + roleName);
} }
role.setName(rep.getName()); role.setName(rep.getName());
role.setDescription(rep.getDescription()); role.setDescription(rep.getDescription());
@ -89,6 +93,6 @@ public class RoleContainerResource {
throw new NotFoundException(); throw new NotFoundException();
} }
role.setDescription(rep.getDescription()); role.setDescription(rep.getDescription());
return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getId()).build()).build(); return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getName()).build()).build();
} }
} }

View file

@ -273,12 +273,12 @@ public class AdapterTest extends AbstractKeycloakTest {
RoleModel realmRole = realmModel.addRole("test"); RoleModel realmRole = realmModel.addRole("test");
realmModel.addScopeMapping(app.getApplicationUser(), realmRole); realmModel.addScopeMapping(app.getApplicationUser(), realmRole);
Assert.assertTrue(realmModel.removeRole(realmRole.getId())); Assert.assertTrue(realmModel.removeRoleById(realmRole.getId()));
Assert.assertFalse(realmModel.removeRole(realmRole.getId())); Assert.assertFalse(realmModel.removeRoleById(realmRole.getId()));
Assert.assertNull(realmModel.getRole(realmRole.getName())); Assert.assertNull(realmModel.getRole(realmRole.getName()));
Assert.assertTrue(app.removeRole(appRole.getId())); Assert.assertTrue(app.removeRoleById(appRole.getId()));
Assert.assertFalse(app.removeRole(appRole.getId())); Assert.assertFalse(app.removeRoleById(appRole.getId()));
Assert.assertNull(app.getRole(appRole.getName())); Assert.assertNull(app.getRole(appRole.getName()));
} }