How can you secure a method to be accessed only by users with a specific role using Spring Security annotations?

  • @RolesAllowed("ROLE_ADMIN")
  • @PreAuthorize("hasRole('ROLE_USER')")
  • @Secured("ROLE_USER")
  • @Authorize("hasAuthority('ROLE_ADMIN')")
You can use the @PreAuthorize annotation with the hasRole expression to specify that a method can only be accessed by users with a specific role. The other options are not the correct format for specifying roles in Spring Security annotations.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *