Latest in branch 5.1
5.1.13
Released 07 Oct 2020
(5 years ago)
SoftwareSpring Security
Branch5.1
Supported
Java/Jakarta EE
Java 8+
Servlet 3.0+
Initial release5.1.0
21 Sep 2018
(7 years ago)
Latest release5.1.13
07 Oct 2020
(5 years ago)
End of
OSS support
31 Oct 2019
(Ended 6 years, 6 months ago)
End of
enterprise support
31 Jan 2021
(Ended 5 years, 3 months ago)
Release noteshttps://github.com/spring-projects/spring-security/releases/tag/5.1.13.RELEASE
Source codehttps://github.com/spring-projects/spring-security/tree/5.1.13.RELEASE
Downloadhttps://github.com/spring-projects/spring-security/releases/tag/5.1.13.RELEASE
Spring Security 5.1 ReleasesView full list

What Is New in Spring Security 5.1

CategoryHighlights
New Features Automatic password storage upgrades via UserDetailsPasswordService and ReactiveUserDetailsPasswordService; OAuth2 Client and Resource Server support for servlet and WebFlux, including authorization_code and client_credentials grants; JWT-encoded bearer token handling; OAuth2 WebClient integration for both servlet and WebFlux; enhanced HTTP Firewall protecting against verb tampering and cross-site tracing; Feature-Policy header support; @Transient authentication tokens; modern default login page.
Improvements ExceptionTranslationFilter can select an AccessDeniedHandler by RequestMatcher; CSRF can exclude specific requests; @WithMockUser now allows custom setup timing; @WithUserDetails works with ReactiveUserDetailsService; @AuthenticationPrincipal now resolves beans and supports errorOnInvalidType; LDAP authentication can be configured with environment variables; X.509 authentication supports custom principal derivation strategies.

How does Spring Security 5.1 simplify password migration for existing users?

Spring Security 5.1 introduces automatic password storage upgrades through the UserDetailsPasswordService (and its reactive counterpart) so that passwords can be re-hashed transparently on successful authentication.

  • Implement UserDetailsPasswordService and return an updated UserDetails with the new encoded password.
  • Register the service as a bean; the framework will invoke it after a successful login if the stored password needs upgrading.
@Service
public class MyPasswordUpgradeService implements UserDetailsPasswordService {
    @Override
    public UserDetails updatePassword(UserDetails user, String newPassword) {
        // persist the new encoded password and return a fresh UserDetails
        return new User(user.getUsername(), newPassword, user.getAuthorities());
    }
}

In practice this means you can move from BCrypt to Argon2 without forcing users to reset passwords.

What new OAuth 2.0 client and resource server capabilities are available in Spring Security 5.1 for servlet and WebFlux?

Spring Security 5.1 adds full OAuth2 Client support for both servlet and WebFlux, including authorization_code and client_credentials grant types, plus JWT-based resource server handling.

  • Servlet: configure spring.security.oauth2.client properties or use OAuth2AuthorizedClientManager for programmatic token acquisition.
  • WebFlux: use ServerOAuth2AuthorizedClientExchangeFilterFunction with the reactive WebClient to obtain tokens automatically.
  • Resource Server: add spring.security.oauth2.resourceserver.jwt to validate JWT bearer tokens without extra code.
// Example WebClient configuration for reactive OAuth2 client
WebClient client = WebClient.builder()
    .filter(new ServerOAuth2AuthorizedClientExchangeFilterFunction(
        clientRegistrationRepository, authorizedClientRepository))
    .build();

This matters if your microservices need to call downstream APIs using OAuth2 without writing custom token handling logic.

How have HTTP security headers and firewall protections been strengthened in Spring Security 5.1?

Spring Security 5.1 enhances the HTTP firewall to block verb tampering and cross-site tracing, and adds first-class support for Feature-Policy and other modern security headers.

  • HTTP Firewall now validates the HTTP method against the request path and rejects unexpected verbs such as TRACE.
  • Feature-Policy header can be added via the HeadersConfigurer to control browser features like fullscreen or geolocation.
  • CSRF configuration now allows selective exclusion of endpoints using a RequestMatcher.
http
    .csrf(csrf -> csrf.ignoringRequestMatchers("/webhook/**"))
    .headers(headers -> headers
        .featurePolicy("geolocation 'self'; fullscreen 'none'"))
    .requestCache().disable();

Watch out for legacy proxies that might rewrite HTTP verbs; the new firewall will reject those requests early.

What testing annotation enhancements does Spring Security 5.1 introduce?

Spring Security 5.1 expands test support by allowing @WithMockUser to control when the security context is set up and enabling @WithUserDetails to work with reactive user services.

  • @WithMockUser(setupBefore = TestExecutionEvent.TEST_EXECUTION) lets you initialize the mock user after JUnit's @Before methods.
  • @WithUserDetails now accepts a ReactiveUserDetailsService bean, making it usable in WebFlux tests.
  • Improvements to @AuthenticationPrincipal allow bean resolution and optional error handling via errorOnInvalidType.
@Test
@WithMockUser(username = "admin", roles = "ADMIN", setupBefore = TestExecutionEvent.TEST_EXECUTION)
void securedEndpointReturnsOk() {
    // test logic here
}

Most teams will see faster test setup and clearer intent when using these annotations.

Frequently Asked Questions

Does Spring Security 5.1 require any code changes to enable automatic password upgrades?
Yes you need to implement UserDetailsPasswordService and register it as a bean so the framework can invoke it after a successful authentication.

Can the new OAuth2 client in 5.1 handle the authorization_code grant out of the box?
Yes the client automatically builds the authorization request and token exchange for authorization_code.

Which HTTP firewall checks were added in 5.1 to prevent verb tampering?
The firewall now validates the HTTP method against the request and blocks unexpected verbs such as TRACE.

How do I exclude a specific endpoint from CSRF protection in 5.1?
Add a RequestMatcher to the CsrfConfigurer using csrf().ignoringRequestMatchers("/webhook/**").

What is the new annotation that allows transient authentication tokens in 5.1?
The @Transient annotation can be placed on a custom Authentication implementation to mark it as non-persistent.

Releases In Branch 5.1

VersionRelease date
5.1.1307 Oct 2020
(5 years ago)
5.1.1205 Aug 2020
(5 years ago)
5.1.1103 Jun 2020
(5 years ago)
5.1.1006 May 2020
(6 years ago)
5.1.901 Apr 2020
(6 years ago)
5.1.805 Feb 2020
(6 years ago)
5.1.704 Nov 2019
(6 years ago)
5.1.605 Aug 2019
(6 years ago)
5.1.502 Apr 2019
(7 years ago)
5.1.413 Feb 2019
(7 years ago)
5.1.310 Jan 2019
(7 years ago)
5.1.228 Nov 2018
(7 years ago)
5.1.115 Oct 2018
(7 years ago)
5.1.021 Sep 2018
(7 years ago)
5.1.0.RC207 Sep 2018
(7 years ago)
5.1.0.RC120 Aug 2018
(7 years ago)
5.1.0.M226 Jul 2018
(7 years ago)
5.1.0.M114 May 2018
(8 years ago)