Introduction to Role-based Access Control in Spring Security
A beginner's quiz on implementing role-based access control using Spring Security.
Questions in this quiz
15 questions on Introduction to Role-based Access Control in Spring Security. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of role-based access control (RBAC) in Spring Security?
- ATo encrypt user data
- BTo manage database connections
- CTo enhance application performance
- DTo control user access based on roles
2.Which annotation is commonly used in Spring Security to specify required roles for a method?
- A@RoleCheck
- B@RolesAllowed
- C@Secured
- D@PreAuthorize
3.In Spring Security, where do you typically define user roles?
- AIn the web.xml file
- BIn the application.properties file
- CIn the security configuration class
- DIn the database
4.What is the default role prefix used by Spring Security?
- AUSER_
- BADMIN_
- CSEC_
- DROLE_
5.Which method in Spring Security is used to configure HTTP security for role-based access?
- Aconfigure(HttpSecurity http)
- BsetRoles(HttpSecurity http)
- CdefineRoles(HttpSecurity http)
- DauthorizeRoles(HttpSecurity http)
6.How can you specify multiple roles for a single method using @PreAuthorize?
- A@PreAuthorize('hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')')
- B@PreAuthorize('hasRole('ROLE_USER, ROLE_ADMIN')')
- C@PreAuthorize('hasAnyRole('ROLE_USER', 'ROLE_ADMIN')')
- D@PreAuthorize('hasRoles('ROLE_USER', 'ROLE_ADMIN')')
7.What is the function of the @EnableGlobalMethodSecurity annotation?
- ATo enable global transaction management
- BTo enable global logging
- CTo enable global exception handling
- DTo enable method-level security annotations
8.Which of the following is a valid way to define a role in Spring Security?
- AROLE-ADMIN
- BROLE_ADMIN
- CADMIN_ROLE
- DADMIN
9.What does the hasRole function check in Spring Security?
- AIf the user has a specific permission
- BIf the user has a specific role
- CIf the user is an admin
- DIf the user is authenticated
10.Which component in Spring Security is responsible for authenticating users?
- ARoleManager
- BAuthenticationManager
- CSecurityContextHolder
- DAccessDecisionManager
11.What is the role of the SecurityContextHolder in Spring Security?
- ATo hold the security context of the current thread
- BTo manage user roles
- CTo encrypt user passwords
- DTo store user session data
12.Which of the following is NOT a valid method for role-based access control in Spring Security?
- A@PostAuthorize
- B@RoleCheck
- C@Secured
- D@PreAuthorize
13.What does the @Secured annotation do in Spring Security?
- ASpecifies roles required to access a method
- BSpecifies the URL patterns to secure
- CSpecifies the encryption algorithm
- DSpecifies the authentication provider
14.What is the purpose of the AccessDecisionManager in Spring Security?
- ATo encrypt user data
- BTo manage user sessions
- CTo decide whether access should be granted to a resource
- DTo manage user authentication
15.Which configuration class is typically extended to set up role-based access control in Spring Security?
- AAccessControlConfigurer
- BRoleSecurityConfigurer
- CWebSecurityConfigurerAdapter
- DSecurityConfigurerAdapter