Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable security in Spring-Boot 2? [duplicate]

In spring-boot-1.x I had the following configuration to disable the basic security in dev mode:

application.properties:
security.basic.enabled=false

application-test.properties:
security.basic.enabled=true

application-prod.properties:
security.basic.enabled=true

As of spring-boot-2.x the property is no longer supported. How can I achieve the same configuration (=disable any security related features and configuration in default profile)?

like image 360
membersound Avatar asked Jul 26 '18 09:07

membersound


People also ask

How do I disable security in spring boot?

basic. enabled=false and management. security. enabled=false should be set to disable the security.

How do I disable Spring Security testing?

One of the ways you can disable Spring Security filters in your tests, is to use the @AutoConfigureMockMvc annotation. @AutoConfigureMockMvc annotation can be applied to a test class to enable and configure auto-configuration of MockMvc.

How do I turn off actuator security?

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).

What is @EnableWebSecurity in spring boot?

The @EnableWebSecurity is a marker annotation. It allows Spring to find (it's a @Configuration and, therefore, @Component ) and automatically apply the class to the global WebSecurity . If I don't annotate any of my class with @EnableWebSecurity still the application prompting for username and password.


1 Answers

Here is configuration class. here permit for all url:

@Configuration
@ConditionalOnProperty(value = "app.security.basic.enabled", havingValue = "false")
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/**").permitAll()
            .anyRequest().authenticated();
}
}
like image 155
GolamMazid Sajib Avatar answered Sep 27 '22 00:09

GolamMazid Sajib