Spring Boot Security: Intermediate Role-Based Access Control
Test your knowledge on implementing role-based access control using Spring Boot Security.
Questions in this quiz
12 questions on Spring Boot Security: Intermediate Role-Based Access Control. Work through them here, then start the quiz to answer them and see your score.
1.In Spring Boot, which annotation is used to specify role-based access control on a method?
- A@PermitAll
- B@Secured
- C@RolesAllowed
- D@PreAuthorize
2.What is the primary purpose of the @EnableGlobalMethodSecurity annotation in Spring Boot?
- ATo enable global transaction management
- BTo enable CORS
- CTo enable method-level security
- DTo configure global exception handling
3.Which of the following is NOT a valid attribute of the @PreAuthorize annotation?
- Avalue
- BhasRole
- ChasPermission
- DhasAuthority
4.How can you define a custom role hierarchy in Spring Security?
- AUsing @RoleHierarchy annotation
- BImplementing RoleHierarchy interface
- CUsing a properties file
- DConfiguring in application.yml
5.Which method in the SecurityConfig class is typically overridden to configure role-based access?
- AconfigureGlobal(AuthenticationManagerBuilder auth)
- Bconfigure(AuthenticationManagerBuilder auth)
- Cconfigure(HttpSecurity http)
- Dconfigure(WebSecurity web)
6.In Spring Security, what does the expression 'hasRole('ADMIN')' check for?
- AIf the user has any role
- BIf the user has a role starting with ADMIN
- CIf the user is an admin
- DIf the user has the ADMIN authority
7.What is the default prefix added to roles in Spring Security?
- AUSER_
- BROLE_
- CAUTH_
- DSEC_
8.Which annotation would you use to allow access to a method for users with either 'USER' or 'ADMIN' roles?
- A@RolesAllowed({"USER", "ADMIN"})
- B@Secured({"USER", "ADMIN"})
- C@PreAuthorize("hasAnyRole('USER', 'ADMIN')")
- D@PermitAll
9.What is the purpose of the @Secured annotation in Spring Security?
- ATo secure endpoints at the method level
- BTo manage session timeouts
- CTo configure CORS settings
- DTo encrypt user passwords
10.In Spring Security, what is the function of the GrantedAuthority interface?
- ATo configure HTTP security
- BTo manage user sessions
- CTo handle authentication exceptions
- DTo represent a user's role or permission
11.Which configuration class is typically used to customize user roles and permissions in Spring Boot?
- ADataSourceConfig
- BWebMvcConfigurer
- CSecurityConfig
- DApplicationConfig
12.How can you restrict access to a REST endpoint to only users with the 'ADMIN' role?
- A@Secured('ROLE_ADMIN')
- BAll of the above
- C@RolesAllowed('ADMIN')
- D@PreAuthorize("hasRole('ADMIN')")