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.
Loading...
Related Quiz
- What is the primary file used to define properties in Spring Boot?
- In a Spring Boot application, you are required to develop a feature where the response body should be customized based on the client's preference. How would you implement this feature using Spring Boot annotations?
- To configure a JWT token store in a Spring Boot application, you need to define a _____ bean in the configuration class.
- Your Spring Boot application has complex business logic that involves interactions between various beans. How would you approach testing such business logic, ensuring that the interactions between beans are correct and that the business logic produces the expected outcomes?
- To externalize configuration properties in Spring Boot, the _____ annotation can be used on a configuration properties class.