Spring Security Basics — Concept Check
Questions on Spring Security Basics. Spring Security protects your application through a chain of servlet filters. Understanding the SecurityFilterChain, SecurityContext, and HttpSecurity DSL is the foundation for any authentication or authorization implementation.
Questions in this quiz
7 questions on Spring Security Basics — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer configures a Spring SecurityFilterChain for a REST API. They disable CSRF and set session management to STATELESS. What is the primary reason for these settings?
- AREST APIs do not use cookies, making CSRF and sessions unnecessary.
- BCSRF protection is only needed for GET requests in REST APIs.
- CStateless services perform better with CSRF and sessions enabled.
- DSessions are only needed for user authentication in REST APIs.
2.In a Spring Security configuration, a developer uses a JWT filter before the default UsernamePasswordAuthenticationFilter. What is the purpose of this configuration?
- ATo ensure JWT tokens are created after authentication.
- BTo disable all authentication mechanisms.
- CTo handle token-based authentication before processing username/password.
- DTo bypass authentication for certain URLs.
3.A developer notices that all users can access '/api/v1/admin/**' endpoints, even though they configured it to require 'ADMIN' role. What might be the issue?
- AThe order of URL access rules might be incorrect.
- BThe JWT filter is not configured correctly.
- CCSRF is not disabled.
- DSession management is not set to STATELESS.
4.In a Spring application, a developer uses SecurityContextHolder to access the authenticated principal. Where is this principal stored?
- AIn a session object.
- BIn a thread-local SecurityContext.
- CIn a global application context.
- DIn a database table.
5.A developer configures their SecurityFilterChain but forgets to disable CSRF for their stateless REST API. What is a likely consequence?
- AThe JWT filter will not function correctly.
- BCSRF protection will be unnecessarily applied, potentially causing issues with token-based authentication.
- CThe application will fail to start due to a configuration error.
- DAll API requests will be rejected due to missing CSRF tokens.
6.A developer uses @AuthenticationPrincipal in a controller method to inject the current user ID. What does this annotation rely on?
- AA custom annotation processor.
- BThe SecurityContext set by the authentication filter.
- CA database query to retrieve the user ID.
- DA session attribute containing the user ID.
7.A developer configures a SecurityFilterChain but observes that all requests require authentication, even those to '/api/v1/auth/**'. What might be the problem?
- AThe JWT filter is not applied correctly.
- BCSRF is not disabled for these endpoints.
- CThe '/api/v1/auth/**' matcher is not placed before the general authentication rule.
- DSession management is incorrectly set to STATELESS.