spring-projects / spring-projects/spring-security

Disable @PreAuthorize filtering

Open
#17,849 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior

I have a Spring Security configuration for permitting all requests:

@Configuration
@EnableWebSecurity
@Profile("no-auth")
public class NoAuthSecurityConfig {

  private static final Logger logger = LoggerFactory.getLogger(NoAuthSecurityConfig.class);

  public NoAuthSecurityConfig() {
  }

  @Bean
  @Order(1)
  public SecurityFilterChain noAuthSecurityFilterChain(final HttpSecurity httpSecurity) throws Exception {
    return httpSecurity
            .csrf(AbstractHttpConfigurer::disable)
            .formLogin(AbstractHttpConfigurer::disable)
            .authorizeHttpRequests(auth ->
                    auth.anyRequest().permitAll()
            )
            .build();
  }
}

Current Behavior

But it's not working for endpoints with: @PreAuthorize. I get:

org.springframework.security.authorization.AuthorizationDeniedException: Access Denied
    at org.springframework.security.authorization.method.ThrowingMethodAuthorizationDeniedHandler.handleDeniedInvocation(ThrowingMethodAuthorizationDeniedHandler.java:38) ~[spring-security-core-6.5.0.jar:6.5.0]
When I remove @PreAuthorize it's working fine. 

Do you know what is the correct way to disable Spring Security in Spring Cloud 2025.0.0?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied NoAuthSecurityConfig and the endpoints using @PreAuthorize; trace which configuration enables method authorization separately from request authorization. Check the Spring Security method-authorization documentation and relevant tests, then define the correct no-auth configuration or documentation change and verify that both request and method authorization behave as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authorization, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.