Mastering Role-Based Access Control with Spring Security
An advanced quiz on implementing role-based access control using Spring Security.
Questions in this quiz
10 questions on Mastering Role-Based Access Control with Spring Security. 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 role-based access control at the method level?
- A@Secured
- B@RolesAllowed
- C@PreAuthorize
- D@PermitAll
2.What is the primary purpose of the GrantedAuthority interface in Spring Security?
- ATo manage user sessions
- BTo store user credentials
- CTo encrypt passwords
- DTo define user roles and permissions
3.Which component is responsible for determining if a user has the necessary roles to access a resource?
- AAuthenticationManager
- BAccessDecisionManager
- CSecurityContextHolder
- DUserDetailsService
4.How can you configure role hierarchy in Spring Security?
- AUsing RoleHierarchyImpl
- BUsing RoleVoter
- CUsing SecurityContext
- DUsing AccessDecisionVoter
5.Which method in the UserDetails interface returns the authorities granted to the user?
- AgetCredentials()
- BgetAuthorities()
- CgetRoles()
- DgetPermissions()
6.What is the role of the @EnableGlobalMethodSecurity annotation in Spring Security?
- ATo configure user authentication
- BTo enable HTTP security
- CTo manage session security
- DTo enable method-level security annotations
7.In Spring Security, which class is typically extended to customize user authentication?
- AUserDetails
- BUserDetailsService
- CAuthenticationProvider
- DSecurityContext
8.Which of the following is a valid way to define a custom role hierarchy in Spring Security?
- AroleHierarchy.setHierarchy("ROLE_ADMIN > ROLE_USER")
- BroleHierarchy.define("ROLE_ADMIN > ROLE_USER")
- CroleHierarchy.assign("ROLE_ADMIN > ROLE_USER")
- DroleHierarchy.createHierarchy("ROLE_ADMIN > ROLE_USER")
9.What is the function of the SecurityContextHolder in Spring Security?
- ATo store user roles
- BTo handle authentication exceptions
- CTo manage security context information
- DTo encrypt user passwords
10.Which annotation would you use to allow access to a method only for users with 'ROLE_ADMIN'?
- A@RolesAllowed("ROLE_ADMIN")
- B@Secured("ROLE_ADMIN")
- C@PreAuthorize("hasRole('ROLE_ADMIN')")
- D@PermitAll