Tuesday 15 July 2014

security - Checking if specific user has a role -


Is there a specific role of specific users (not what is logged in)? (IfAnyGranted) (user, "ROLE_ADMIN")) // if you get user with user ID = user.at (1) // id 1) / //

  I want this line to be implemented in any way ...}  

Thanks in advance.

I believe your user domain class values ​​your role class this way:

/ P>

  class user {static HasMany = [officers: role] // ....} role of class {static relative = user string description string authority // ....}  

Then your code is simple to check the role:

  user = user.at (1) if (user.authorities.any {it.authority == " ROLE_ADMIN "}) {// User Is the administrator}  

An updated answer can be found.


No comments:

Post a Comment