spring-projects / spring-projects/spring-security
Disable @PreAuthorize filtering
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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