spring-projects / spring-projects/spring-security
HttpSecurity bean has no option to disable defaults
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Starting from 5.7 the WebSecurityConfigurerAdapter has been deprecated in favour of using a custom bean for creating a SecurityFilterChain that will inject an HttpSecurity and build it.
The WebSecurityConfigurerAdapter has a constructor field disableDefaults which was used to determine whether defaults should be applied to the configuration or not.
When that flag was set to true then the default configuration and default configurers would not be applied to it. When using the new recommended approach there is no way to disable these defaults.
What would be the recommended approach for disabling the defaults.
Does it perhaps make sense to have an interface like:
public interface HttpSecurityProvider {
default HttpSecurity create() {
return create(false);
}
HttpSecurity create(boolean disableDefaults);
}
Then instead of doing:
@Configuration
public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.anyRequest().authenticated()
)
.httpBasic(withDefaults());
return http.build();
}
}
we can do:
@Configuration
public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurityProvider httpProvider) throws Exception {
HttpSecurity http = httpProvider.create(true);
http
.authorizeHttpRequests((authz) -> authz
.anyRequest().authenticated()
)
.httpBasic(withDefaults());
return http.build();
}
}
The approach is only a potential idea. It doesn't have to look like that. However, I do think that it might make sense to expose a functionality that was possible to be used like before.
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 by comparing WebSecurityConfigurerAdapter's disableDefaults behavior with the HttpSecurity and SecurityFilterChain entry points described in the issue. Determine whether a supported way to disable defaults should be exposed and define the expected configuration behavior before proposing an API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100