Merge pull request #157 from patriot1burke/master
role name instead of id
This commit is contained in:
commit
7294235534
13 changed files with 37 additions and 33 deletions
|
@ -137,7 +137,7 @@ module.controller('ApplicationRoleDetailCtrl', function($scope, realm, applicati
|
|||
ApplicationRole.update({
|
||||
realm : realm.realm,
|
||||
application : application.name,
|
||||
roleId : role.id
|
||||
role : role.name
|
||||
}, $scope.role, function() {
|
||||
$scope.changed = false;
|
||||
role = angular.copy($scope.role);
|
||||
|
@ -160,7 +160,7 @@ module.controller('ApplicationRoleDetailCtrl', function($scope, realm, applicati
|
|||
$scope.role.$remove({
|
||||
realm : realm.realm,
|
||||
application : application.name,
|
||||
roleId : $scope.role.id
|
||||
role : $scope.role.name
|
||||
}, function() {
|
||||
$location.url("/realms/" + realm.realm + "/applications/" + application.name + "/roles");
|
||||
Notifications.success("The role has been deleted.");
|
||||
|
|
|
@ -818,7 +818,7 @@ module.controller('RoleDetailCtrl', function($scope, realm, role, Role, $locatio
|
|||
} else {
|
||||
Role.update({
|
||||
realm : realm.realm,
|
||||
roleId : role.id
|
||||
role : role.name
|
||||
}, $scope.role, function() {
|
||||
$scope.changed = false;
|
||||
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() {
|
||||
$scope.role.$remove({
|
||||
realm : realm.realm,
|
||||
roleId : $scope.role.id
|
||||
role : $scope.role.name
|
||||
}, function() {
|
||||
$location.url("/realms/" + realm.realm + "/roles");
|
||||
Notifications.success("The role has been deleted.");
|
||||
|
|
|
@ -64,7 +64,7 @@ module.factory('RoleLoader', function(Loader, Role, $route, $q) {
|
|||
return Loader.get(Role, function() {
|
||||
return {
|
||||
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 {
|
||||
realm : $route.current.params.realm,
|
||||
application : $route.current.params.application,
|
||||
roleId : $route.current.params.role
|
||||
role : $route.current.params.role
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -184,9 +184,9 @@ module.factory('RealmRoles', 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',
|
||||
roleId : '@roleId'
|
||||
role : '@role'
|
||||
}, {
|
||||
update : {
|
||||
method : 'PUT'
|
||||
|
@ -195,10 +195,10 @@ module.factory('Role', 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',
|
||||
application : "@application",
|
||||
roleId : '@roleId'
|
||||
role : '@role'
|
||||
}, {
|
||||
update : {
|
||||
method : 'PUT'
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
</tfoot>
|
||||
<tbody>
|
||||
<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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
</tfoot>
|
||||
<tbody>
|
||||
<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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -11,7 +11,7 @@ public interface RoleContainerModel {
|
|||
|
||||
RoleModel addRole(String name);
|
||||
|
||||
boolean removeRole(String id);
|
||||
boolean removeRoleById(String id);
|
||||
|
||||
List<RoleModel> getRoles();
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ public class ApplicationAdapter implements ApplicationModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(String id) {
|
||||
public boolean removeRoleById(String id) {
|
||||
RoleEntity role = em.find(RoleEntity.class, id);
|
||||
if (role == null) {
|
||||
return false;
|
||||
|
|
|
@ -841,7 +841,7 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(String id) {
|
||||
public boolean removeRoleById(String id) {
|
||||
RoleEntity role = em.find(RoleEntity.class, id);
|
||||
if (role == null) {
|
||||
return false;
|
||||
|
|
|
@ -156,7 +156,7 @@ public class ApplicationAdapter implements ApplicationModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(String id) {
|
||||
public boolean removeRoleById(String id) {
|
||||
try {
|
||||
getIdm().remove(getIdm().lookupIdentityById(Role.class, id));
|
||||
return true;
|
||||
|
|
|
@ -564,7 +564,7 @@ public class RealmAdapter implements RealmModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(String id) {
|
||||
public boolean removeRoleById(String id) {
|
||||
try {
|
||||
getIdm().remove(getIdm().lookupIdentityById(Role.class, id));
|
||||
return true;
|
||||
|
|
|
@ -42,36 +42,40 @@ public class RoleContainerResource {
|
|||
return roles;
|
||||
}
|
||||
|
||||
@Path("roles/{id}")
|
||||
@Path("roles/{role-name}")
|
||||
@GET
|
||||
@NoCache
|
||||
@Produces("application/json")
|
||||
public RoleRepresentation getRole(final @PathParam("id") String id) {
|
||||
RoleModel roleModel = roleContainer.getRoleById(id);
|
||||
public RoleRepresentation getRole(final @PathParam("role-name") String roleName) {
|
||||
RoleModel roleModel = roleContainer.getRole(roleName);
|
||||
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());
|
||||
rep.setId(roleModel.getId());
|
||||
return rep;
|
||||
}
|
||||
|
||||
@Path("roles/{id}")
|
||||
@Path("roles/{role-name}")
|
||||
@DELETE
|
||||
@NoCache
|
||||
public void deleteRole(final @PathParam("id") String id) {
|
||||
if (!roleContainer.removeRole(id)) {
|
||||
public void deleteRole(final @PathParam("role-name") String roleName) {
|
||||
RoleModel role = roleContainer.getRole(roleName);
|
||||
if (role == null) {
|
||||
throw new NotFoundException("Could not find role: " + roleName);
|
||||
}
|
||||
if (!roleContainer.removeRoleById(role.getId())) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("roles/{id}")
|
||||
@Path("roles/{role-name}")
|
||||
@PUT
|
||||
@Consumes("application/json")
|
||||
public void updateRole(final @PathParam("id") String id, final RoleRepresentation rep) {
|
||||
RoleModel role = roleContainer.getRoleById(id);
|
||||
public void updateRole(final @PathParam("role-name") String roleName, final RoleRepresentation rep) {
|
||||
RoleModel role = roleContainer.getRole(roleName);
|
||||
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.setDescription(rep.getDescription());
|
||||
|
@ -89,6 +93,6 @@ public class RoleContainerResource {
|
|||
throw new NotFoundException();
|
||||
}
|
||||
role.setDescription(rep.getDescription());
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getId()).build()).build();
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getName()).build()).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -273,12 +273,12 @@ public class AdapterTest extends AbstractKeycloakTest {
|
|||
RoleModel realmRole = realmModel.addRole("test");
|
||||
realmModel.addScopeMapping(app.getApplicationUser(), realmRole);
|
||||
|
||||
Assert.assertTrue(realmModel.removeRole(realmRole.getId()));
|
||||
Assert.assertFalse(realmModel.removeRole(realmRole.getId()));
|
||||
Assert.assertTrue(realmModel.removeRoleById(realmRole.getId()));
|
||||
Assert.assertFalse(realmModel.removeRoleById(realmRole.getId()));
|
||||
Assert.assertNull(realmModel.getRole(realmRole.getName()));
|
||||
|
||||
Assert.assertTrue(app.removeRole(appRole.getId()));
|
||||
Assert.assertFalse(app.removeRole(appRole.getId()));
|
||||
Assert.assertTrue(app.removeRoleById(appRole.getId()));
|
||||
Assert.assertFalse(app.removeRoleById(appRole.getId()));
|
||||
Assert.assertNull(app.getRole(appRole.getName()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue