Spring Security: ignoring resources different behavior with and without actuator
See original GitHub issueHere is a simple project that demonstrates the problem: https://github.com/ralscha/ignoring
Spring Boot adds by default ignore rules for /css/, /js/ and /images/**.
Creating filter chain: Ant [pattern='/css/**'], []
Creating filter chain: Ant [pattern='/js/**'], []
Creating filter chain: Ant [pattern='/images/**'], []
When there is a custom WebSecurityConfigurerAdapter in the application these rules will not be applied which is what I want.
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
class SecurityConfig extends WebSecurityConfigurerAdapter {
.....
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/img2.png");
}
.....
}
Creating filter chain: Ant [pattern='/img2.png'], []
Creating filter chain: Ant [pattern='/**'], .......
But as soon as you add the actuator as a dependency this behavior changes
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
The presence of a custom WebSecurityConfigurerAdapter no longer overwrites the default ignore rules and the code in the configure method will be ignored.
Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/css/**'], Ant [pattern='/js/**'], Ant [pattern='/images/**'], Ant [pattern='/**/favicon.ico'], Ant [pattern='/error']]], []
Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]],......
To override the default rules you need to add a security.ignored property in the applicaiton.properties or application.yml file
security:
ignored:
- /img2.png
Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/img2.png'], Ant [pattern='/error']]], []
Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]], .....
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Spring Security without the WebSecurityConfigurerAdapter
The warning is about calling the ignoring method, whether it is from the WebSecurityCustomizer or WebSecurityConfigurerAdapter . When an ...
Read more >Spring Websecurity throwing 401 on 'ignored' resource when ...
A deep dive intro DEBUG logs further and I have found the issue. When throwing an exception with a HTTP_STATUS code, Spring actually ......
Read more >Spring Boot Security Auto-Configuration - Baeldung
For example, almost each Spring Boot application is started with Actuator in the classpath. This causes problems because another auto-configuration class ...
Read more >Conditionally Disabling or Overriding Spring Boot Security ...
In this article, we'll have a look at how to disable Security in Spring Boot application and how to customize Security Configuration.
Read more >Spring Boot Admin Reference Guide - GitHub Pages
The following steps uses Eureka, but other Spring Cloud Discovery ... By default the logfile is not accessible via actuator endpoints and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks good now. I tested it with the 1.5.0 snapshot and it does no longer make a difference if the actuator is on the classpath or not. Thanks for the change.
Defaults. Without actuator on the classpath 1.4.2.RELEASE
1.5.0.BUILD-SNAPSHOT
Defaults. With actuator on the classpath 1.4.2.RELEASE
1.5.0.BUILD-SNAPSHOT
With
security.ignored=none
. Without actuator on the classpath 1.4.2.RELEASE1.5.0.BUILD-SNAPSHOT
With
security.ignored=none
. With actuator on the classpath 1.4.2.RELEASE1.5.0.BUILD-SNAPSHOT
With custom WebSecurityConfigurerAdapter. Without actuator on the classpath 1.4.2.RELEASE
1.5.0.BUILD-SNAPSHOT
With custom WebSecurityConfigurerAdapter. With actuator on the classpath 1.4.2.RELEASE
1.5.0.BUILD-SNAPSHOT
With
security.ignored=none
and custom WebSecurityConfigurerAdapter. Without actuator on the classpath 1.4.2.RELEASE1.5.0.BUILD-SNAPSHOT
With
security.ignored=none
and custom WebSecurityConfigurerAdapter. With actuator on the classpath 1.4.2.RELEASE1.5.0.BUILD-SNAPSHOT
Custom WebSecurityConfigurerAdapter used in this example
After further investigating this issue I figured out that my statement about ignoring the rule from the configure method is wrong. The framework always adds the ignore rule from the
public void configure(WebSecurity web)
methodBut there is a difference when the actuator is on the classpath or not.
Default. Without actuator on the classpath and without a custom WebSecurityConfigurerAdapter
With a custom
WebSecurityConfigurerAdapter
and without actuator on the classpathCreating filter chain: Ant [pattern='/img2.png'], []
With a custom WebSecurityConfigurerAdapter and with the actuator on the classpath
The problem is that the
org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration
re-adds the default ignore rules.A solution is to set security.ignored to none.
Not exactly the same as without the actuator because it still adds the ignore rule for /error