QuizzesAdvanced Role-Based Access Control with Spring Security
advanced
spring

Advanced Role-Based Access Control with Spring Security

Explore advanced concepts of implementing role-based access control using Spring Security.

20 minutes 10 questions Pass at 70%
Time Limit
20 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

10 questions on Advanced Role-Based Access Control with Spring Security. Work through them here, then start the quiz to answer them and see your score.

  1. 1.In Spring Security, which annotation is used to specify that a method can only be accessed by users with a specific role?

    • A@PermitAll
    • B@Secured
    • C@PreAuthorize
    • D@RolesAllowed
  2. 2.What is the primary purpose of the `GrantedAuthority` interface in Spring Security?

    • ATo manage user sessions
    • BTo represent an authority granted to the user
    • CTo define user credentials
    • DTo encrypt user passwords
  3. 3.How can you configure role hierarchy in Spring Security?

    • ABy modifying the `SecurityContext`
    • BUsing the `RoleHierarchyImpl` class
    • CUsing a custom filter
    • DBy overriding the `UserDetailsService`
  4. 4.Which method in `UserDetails` interface is used to retrieve the roles assigned to a user?

    • AgetPermissions()
    • BgetAuthorities()
    • CgetUserRoles()
    • DgetRoles()
  5. 5.What is the effect of setting `@PreAuthorize("hasRole('ADMIN')")` on a method?

    • AThe method can be accessed by any authenticated user
    • BThe method is publicly accessible
    • CThe method can be accessed only by users with the ADMIN role
    • DThe method is restricted to users with any role
  6. 6.Which component is responsible for checking if a user has the required roles to access a resource in Spring Security?

    • AUserDetailsService
    • BAuthenticationManager
    • CAccessDecisionManager
    • DSecurityContextHolder
  7. 7.How can you enable global method security in a Spring Boot application?

    • ABy using `@EnableWebSecurity`
    • BBy configuring a custom filter
    • CBy adding `@EnableGlobalMethodSecurity` on a configuration class
    • DBy setting a property in `application.properties`
  8. 8.In a Spring Security configuration, how can you allow access to a URL pattern only for users with a specific role?

    • AUsing `http.authorizeRequests().antMatchers('/admin/**').hasRole('ADMIN')`
    • BUsing `http.formLogin()`
    • CUsing `http.sessionManagement()`
    • DUsing `http.csrf().disable()`
  9. 9.What is the purpose of the `SecurityContextHolder` in Spring Security?

    • ATo encrypt passwords
    • BTo hold the security context of the current execution thread
    • CTo store user credentials
    • DTo manage user sessions
  10. 10.Which of the following is a correct way to define a custom role hierarchy in Spring Security?

    • AUsing `UserDetailsService`
    • BUsing `RoleHierarchyImpl` and setting it on `AccessDecisionManager`
    • CUsing `SecurityContextHolder`
    • DUsing `AuthenticationManager`