Recall & Review
beginner
What is the purpose of the
@Secured annotation in Spring Boot?The
@Secured annotation is used to specify security roles that are allowed to access a method or class. It restricts access based on user roles.Click to reveal answer
beginner
How do you specify multiple roles with
@Secured?You provide an array of role names inside
@Secured, like @Secured({"ROLE_ADMIN", "ROLE_USER"}). The method is accessible if the user has any one of these roles.Click to reveal answer
beginner
Where can you place the
@Secured annotation in your code?You can place
@Secured on methods or on classes. When placed on a class, it applies to all methods inside that class.Click to reveal answer
intermediate
What must be enabled in Spring Security configuration to use
@Secured annotations?You must enable method security by adding
@EnableMethodSecurity(securedEnabled = true) in your configuration class.Click to reveal answer
intermediate
What happens if a user without the required role tries to access a method annotated with
@Secured?Spring Security will deny access and throw an
AccessDeniedException, usually resulting in a 403 Forbidden HTTP response.Click to reveal answer
What does
@Secured({"ROLE_ADMIN"}) mean?✗ Incorrect
The annotation restricts access to users who have the ROLE_ADMIN authority.
Where do you enable support for
@Secured annotations in Spring Boot?✗ Incorrect
You must enable method security with
@EnableMethodSecurity(securedEnabled = true) to use @Secured.If
@Secured is placed on a class, what happens?✗ Incorrect
The annotation secures all methods inside the class.
Can
@Secured accept multiple roles?✗ Incorrect
@Secured accepts an array like {"ROLE_USER", "ROLE_ADMIN"}.What exception is thrown if access is denied by
@Secured?✗ Incorrect
Spring Security throws
AccessDeniedException when a user lacks required roles.Explain how the
@Secured annotation controls access in a Spring Boot application.Think about who can use the method and what happens if they can't.
You got /4 concepts.
Describe the steps to secure a method using
@Secured in Spring Boot.Consider configuration and annotation placement.
You got /4 concepts.