Spring Security: method to check if a user has a Hierarchical Role

Viewed 1786

how i can check if a user has a hierarchical role at runtime ? I know this solution for the url authorization @PreAuthorize("hasRole('ROLE_ADMIN')") but inside a method if i have to check the role ?

For example:

ROLE_ADMIN > ROLE_USER > ROLE_GUEST

if (user.hasRole('ROLE_USER')){
    do something;
}

In this example the condition must to be true if the user has the ROLE_ADMIN because in hierarchical roles ROLE_ADMIN > ROLE_USER.

Thanks

1 Answers
Related