Spring Security: Intermediate Role-Based Access Control Mastery
Assess your understanding of implementing role-based access control using Spring Security.
Questions in this quiz
12 questions on Spring Security: Intermediate Role-Based Access Control Mastery. Work through them here, then start the quiz to answer them and see your score.
1.In Spring Security, which annotation is used to specify that a method can only be accessed by users with a specific role?
- A@PreAuthorize
- B@PermitAll
- C@Secured
- D@RolesAllowed
2.What is the primary purpose of the `GrantedAuthority` interface in Spring Security?
- ATo encrypt user passwords
- BTo manage user sessions
- CTo represent an authority granted to a user
- DTo define user credentials
3.Which method in the `UserDetails` interface returns the roles assigned to a user?
- AgetPermissions()
- BgetAuthorities()
- CgetRoles()
- DgetCredentials()
4.How can you restrict access to a controller method to users with the 'ADMIN' role using annotations?
- A@PreAuthorize('hasRole('ADMIN')')
- B@Secured('ADMIN')
- C@PermitAll
- D@RolesAllowed('ADMIN')
5.Which configuration class is typically extended to customize role-based access control in a Spring Boot application?
- ASecurityConfiguration
- BSecurityContextHolder
- CWebSecurityConfigurerAdapter
- DAuthenticationManagerBuilder
6.What is the role of the `@EnableGlobalMethodSecurity` annotation in Spring Security?
- AIt manages user sessions
- BIt encrypts passwords
- CIt enables method-level security annotations
- DIt configures global security settings
7.In Spring Security, what does the `hasAuthority('ROLE_USER')` expression check for?
- AIf the user has a specific role
- BIf the user has a specific permission
- CIf the user is an admin
- DIf the user is authenticated
8.Which component is responsible for loading user-specific data in Spring Security?
- AAccessDecisionManager
- BSecurityContextHolder
- CUserDetailsService
- DAuthenticationProvider
9.What is the default role prefix used by Spring Security when checking roles?
- AROLE_
- BUSER_
- CAUTH_
- DADMIN_
10.How can you specify multiple roles for a method using the @Secured annotation?
- A@Secured('ROLE_USER, ROLE_ADMIN')
- B@Secured({'ROLE_USER', 'ROLE_ADMIN'})
- C@Secured('ROLE_USER') @Secured('ROLE_ADMIN')
- D@Secured(['ROLE_USER', 'ROLE_ADMIN'])
11.Which class in Spring Security is commonly used to build custom authentication logic?
- AAuthenticationProvider
- BAccessDecisionManager
- CSecurityContextHolder
- DUserDetailsService
12.What is the purpose of the `SecurityContextHolder` in Spring Security?
- ATo handle authentication exceptions
- BTo manage user roles
- CTo store security context information
- DTo encrypt passwords