Spring_Security_Interview_Problems
Spring_Security_Interview_Problems
How does Spring Security's filter chain work and how can you customize it?
Spring Security uses a chain of filters to intercept and process requests before reaching
controllers.
Key filters include:
SecurityContextPersistenceFilter, UsernamePasswordAuthenticationFilter,
ExceptionTranslationFilter, FilterSecurityInterceptor.
Customization options:
Add or remove filters via HttpSecurity or SecurityFilterChain.
Create custom filters by implementing OncePerRequestFilter or GenericFilterBean.
Use DSL to define filter order and access rules.
Filters are ordered to ensure consistent behavior during authentication and
authorization.
How would you integrate Spring Security with OAuth2 for single sign-on (SSO)?
Use Spring Security’s OAuth2 client support:
spring-security-oauth2-client (for login via Google, GitHub, etc.).
spring-security-oauth2-resource-server (for JWT and introspection-based
authorization).
Steps:
Configure client registration in application.yml (client-id, client-secret, scopes).
Use @EnableOAuth2Login for browser-based SSO.
Configure WebSecurityConfigurer to allow redirects and token validation.
Customize OAuth2UserService to map external identities to internal roles.