Skip to content

Spring Security 6.1.4 breaks authentication security context #13866

Closed
@m-ignatov

Description

@m-ignatov

Describe the bug
After updating to Spring Security 6.1.4 (as part of Spring Boot 3.1.4), the authentication context is not being populated and SecurityContextHolder.getContext().getAuthentication() returns null.

The issue seems to come from updating this concrete dependency:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>6.1.4</version>
</dependency>

Version 6.1.3 works fine.

After further investigation, it turns out this particular code in our application causes the authentication object to be null, but not sure why:

@Configuration
@EnableMethodSecurity
public class MethodSecurityConfig {

  @Bean
  static MethodSecurityExpressionHandler methodSecurityExpressionHandler() {
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    return new DefaultMethodSecurityExpressionHandler();
  }
}

Expected behavior
Authentication context should be populated from the HTTP request Authentication header (JWT Bearer token).
The setup is a standard Spring Boot application with Spring MVC and Spring Security (Web Security Config).

Let me know if you need more information.

Regards,
Momchil

Metadata

Metadata

Labels

status: invalidAn issue that we don't feel is validtype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions