Authentication & Authorisation — Concept Check
Questions on Authentication & Authorisation. Authentication verifies who the caller is (UserDetailsService, in-memory, LDAP); authorisation decides what resources they can access (@PreAuthorize, security DSL).
Questions in this quiz
8 questions on Authentication & Authorisation — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer configures a Spring Security application and notices that all users, regardless of their roles, can access the '/admin/**' endpoints. What might be the cause?
- AThe csrf protection is disabled.
- BThe session management is set to STATELESS.
- CThe PasswordEncoder is not configured.
- DThe SecurityFilterChain is missing role-based restrictions.
2.In a Spring application, a method annotated with @PreAuthorize("hasRole('USER')") is accessible to all users. What could be the issue?
- AThe method is not part of a @Service class.
- BThe SecurityFilterChain is not configured.
- CThe @EnableMethodSecurity annotation is missing.
- DThe UserDetailsService is not implemented.
3.A user reports they can't access their own orders using the getOrdersByUser method despite having the correct role. What could be wrong?
- AThe method lacks @PreAuthorize annotation.
- BThe userId parameter is not correctly matched with the principal.
- CThe SecurityFilterChain is improperly configured.
- DThe UserDetailsService is not loading roles correctly.
4.What happens if the PasswordEncoder used in DaoAuthenticationProvider does not match the encoding of stored passwords?
- AThe application will throw a runtime exception.
- BAuthentication will succeed without checking passwords.
- CUser roles will not be loaded correctly.
- DAuthentication will always fail.
5.A developer wants to ensure that only active users can authenticate. How should this be achieved in Spring Security?
- ASet credentialsExpired to true for inactive users.
- BImplement a custom AuthenticationProvider.
- CUse @PreAuthorize to check user status.
- DUse accountExpired property in UserDetails.
6.Why might a developer choose to disable CSRF protection in a REST API using Spring Security?
- AIt enhances security for stateful sessions.
- BIt simplifies the configuration process.
- CIt allows easier integration with JWT.
- DCSRF is not a concern for stateless APIs.
7.In Spring Security, what is the role of a SecurityFilterChain?
- AIt defines HTTP-level security rules and filters requests.
- BIt manages user sessions and authentication tokens.
- CIt loads user details from a database.
- DIt encodes and decodes passwords for authentication.
8.A developer mistakenly believes that @PostAuthorize can prevent method execution if conditions are not met. Why is this incorrect?
- A@PostAuthorize only filters the result after execution.
- B@PostAuthorize is only for methods returning collections.
- C@PostAuthorize can only be used with @Service classes.
- D@PostAuthorize requires a custom PermissionEvaluator.