We have a solution implemented based on this article and this post. Now we need to enhance this solution. Here is the use case.
There are various permissions like CREATE_USER
, CREATE_ORG
etc... But based on user roles we need to apply certain restrictions. For example ROLE_ADMIN
as well as ROLE_ORG_ADMIN
can create users. But ROLE_ORG_ADMIN
can only create users with some specific permission (or ROLE_ORG_ADMIN
should not be able to create a user with ROLE_ADMIN
privileges)
ROLE
is simply a group of permissions- User is associated with a role and on login
org.springframework.security.core.userdetails.User.authorities
is set with permissions instead ofROLE
We have REST application with token based authentication.
@RequestMapping(value = "/users",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@Secured(AuthoritiesConstants.CREATE_USER)
public ResponseEntity<?> createUser(@RequestBody ...)
Now we have an admin interface where we control these restrictions from UI, in UI for creating user we do not display ROLE_ADMIN
in select list for ROLE_ORG_ADMIN
. We are going to expose api for third party. We are not sure how this can be done at api level.
POST /api/users
{
"id": null,
"login": "name",
"firstName": "first",
"lastName": "Last",
"email": "first.last@email.com",
"activated": true,
"langKey": "en",
"createdBy": null,
"createdDate": null,
"lastModifiedBy": null,
"lastModifiedDate": null,
"resetDate": null,
"resetKey": null,
"authorities": [
"ROLE_ORG_ADMIN",
"ROLE_ADMIN"
]
}
What we want to do is to restrict a user with role ROLE_ORG_ADMIN
creating users with role ROLE_ADMIN
. Both ROLE_ORG_ADMIN
and ROLE_ADMIN
has permission CREATE_USER
. If the current user role is not ROLE_ADMIN
api should respond with access denied when tried to create a user with role ROLE_ADMIN
. Please help.