Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I annotate a method with Spring Security so that a caller is required to have one of a list of roles?

I am using Java annotations to grant permissions to a particular method. So far I have not found a way to make my method accessible to multiple roles. Single role works fine with @Secured("ROLE_CUSTOMER"). Is there a way to do hasRole('role1','role2')?

like image 553
Sankalp Avatar asked Sep 05 '11 12:09

Sankalp


1 Answers

Found an exact solution to the problem:

@PreAuthorize("hasAnyRole('ROLE_CUSTOMER','ROLE_OFFICEADMIN','ROLE_EMPLOYEE')") 
like image 83
Sankalp Avatar answered Sep 22 '22 09:09

Sankalp