How do you configure password policies in Spring Security?
Enforce password rules at registration with a custom Bean Validation constraint, hash with a PasswordEncoder, and screen breached passwords using Spring Security 6.3.
2,886 posts about Java: questions with answers, tutorials and articles, newest first.
Enforce password rules at registration with a custom Bean Validation constraint, hash with a PasswordEncoder, and screen breached passwords using Spring Security 6.3.
Learn why Spring Security uses PasswordEncoder, how encode and matches work, which implementations to pick, and how to migrate hashes safely.
Configure logout in Spring Security 6 and 7 using the lambda DSL, with CSRF-safe POST logout, custom handlers, redirects and stateless JWT APIs.
@Secured guards Spring methods by required authorities. See how to enable it, the ROLE_ prefix rule, testing and when to use @PreAuthorize instead.
See how Spring Security 6 validates CSRF tokens, how to pick a token repository, exempt endpoints, disable protection safely and test it.
SecurityContextHolder gives your code access to the authenticated user's SecurityContext. Learn the storage strategies and how to propagate the context to other threads.
Enable @EnableMethodSecurity and secure service methods with @PreAuthorize and SpEL. Covers roles, authorities, filters and testing.
Compare basic and form-based authentication: how credentials travel, sessions, logout, security risks and when to use each, with Spring Security 6 code.
Create a custom UserDetailsService that loads users from a database and plug it into Spring Security 6 with a PasswordEncoder and SecurityFilterChain.
UserDetailsService loads a user by username and returns the hash and authorities. Spring Security then verifies the password.
Modern Spring Security setup: SecurityFilterChain, users, password encoding, URL and method authorization and JWT resource server.
@SessionAttributes keeps a form object in the session across requests of one Spring MVC controller. See the multi-step form pattern and common pitfalls.
Set server.servlet.session.timeout, handle expired sessions with Spring Security 6 and override the timeout per session. Includes Spring Session and cookie settings.
HttpSession gives stateless HTTP a server-side memory per user. See how session IDs work, the key methods, timeouts and how to secure sessions.
Configure Spring Security sessions with creation policies, fixation protection, concurrent session limits and Spring Session for clustered applications.
Spring's @SessionScope creates one bean per HTTP session, ideal for per-user state like a shopping cart. See the proxy behaviour, examples and alternatives.
Manage user sessions in Spring with HttpSession, session scope, Boot cookie and timeout properties, Spring Security controls and Spring Session with Redis.
@EnableCaching switches on Spring's cache proxies so @Cacheable, @CachePut and @CacheEvict work. See providers, configuration and pitfalls such as self-invocation.
Learn how Spring builds cache keys by default and how to implement a custom KeyGenerator, apply it to @Cacheable and set it as the application default.
Ehcache stores the results of Spring @Cacheable methods in heap, off-heap or disk tiers. See the Spring Boot setup, a full example and alternatives.