Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot 3.2.5 @Preauthorize gives forbidden #40496

Closed
Kryptonian-C opened this issue Apr 24, 2024 · 3 comments
Closed

Spring boot 3.2.5 @Preauthorize gives forbidden #40496

Kryptonian-C opened this issue Apr 24, 2024 · 3 comments

Comments

@Kryptonian-C
Copy link

Kryptonian-C commented Apr 24, 2024

Hi Team,
After upgrading to Spring boot 3.2.5 The methods annotated with @Preauthorize("isAuthenticated()") starts throwing Forbidden error.
If I simply downgrade to 3.2.4 then everything works normal.

My Security class looks like below.

@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class GraphqlSecurityConfig {

  private AuthenticationManager authenticationManager;

  private final SecurityContextRepository securityContextRepository;

  @Autowired
  public GraphqlSecurityConfig(
      AuthenticationManager authenticationManager,
      SecurityContextRepository securityContextRepository) {
    this.authenticationManager = authenticationManager;
    this.securityContextRepository = securityContextRepository;
  }

  @Bean
  public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity) {

    return httpSecurity
        .csrf(ServerHttpSecurity.CsrfSpec::disable)
        .httpBasic(ServerHttpSecurity.HttpBasicSpec::disable)
        .formLogin(ServerHttpSecurity.FormLoginSpec::disable)
        .authenticationManager(authenticationManager)
        .securityContextRepository(securityContextRepository)
        .authorizeExchange(it -> it.pathMatchers("*").permitAll())
        .build();
  }
}

AuthenticationManager and SecurityContextRepository have the logic for token validation which takes the token from the Authorization header and creates a UsernamePasswordAuthenticationToken.

Also, in 3.2.5 If we remove the @PreAuthorize then I am able to access the Principal and Credentials from the ReactiveSecurityContextHolder.getContext() after passing the Authorization in the header.

And simply downgrading to 3.2.4 everything works fine.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 24, 2024
@wilkinsona
Copy link
Member

Thanks for the report. I suspect that this isn't caused by Spring Boot itself but, most likely, by a change in Spring Security. That said, it's hard to be certain as we don't have the full picture here. For example, you haven't shown the code where you're using @PreAuthorize.

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Apr 24, 2024
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label May 1, 2024
@spring-projects-issues
Copy link
Collaborator

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2024
@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants