Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.0 disable default security

I want to use Spring Security for JWT authentication. But it comes with default authentication. I am trying to disable it, but the old approach of doing this - disabling it through application.properties - is deprecated in 2.0.

This is what I tried:

@Configuration public class StackWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {      @Override     protected void configure(HttpSecurity http) throws Exception {         http.httpBasic().disable();         // http.authorizeRequests().anyRequest().permitAll(); // Also doesn't work.     } } 

How can I simply disable basic security?

UPDATE
It might be nice to know that I am not using web mvc but web flux.

Screenshot:
Basic login form

like image 966
Jan Wytze Avatar asked Nov 13 '17 21:11

Jan Wytze


People also ask

How do I disable spring boot default security?

In Spring Boot 2, if we want our own security configuration, we can simply add a custom WebSecurityConfigurerAdapter. This will disable the default auto-configuration and enable our custom security configuration.

How do I ignore Spring Security?

When using permitAll it means every authenticated user, however you disabled anonymous access so that won't work. What you want is to ignore certain URLs for this override the configure method that takes WebSecurity object and ignore the pattern.

How do I disable Spring Security for actuator endpoints?

You can enable or disable an actuator endpoint by setting the property management. endpoint. <id>. enabled to true or false (where id is the identifier for the endpoint).


1 Answers

According to the new updates in Spring 2.0, if Spring Security is on the classpath, Spring Boot will add @EnableWebSecurity.So adding entries to the application.properties ain't gonna work (i.e it is no longer customizable that way). For more information visit the official website Security changes in Spring Boot 2.0

Albeit not sure about your requirement exactly, I could think of one workaround like the following:-

@Configuration @EnableWebSecurity public class SecurityConfiguration  extends WebSecurityConfigurerAdapter{     @Override     protected void configure(HttpSecurity http) throws Exception{         http.authorizeRequests().antMatchers("/").permitAll();     } } 

Hope this helps.

like image 102
Sen Avatar answered Sep 17 '22 17:09

Sen