Disable Basic Authentication while using Spring Security Java configuration

前端 未结 6 1748
渐次进展
渐次进展 2020-12-01 12:55

I am trying to secure a web application using Spring Security java configuration.

This is how the configuration looks:-



        
6条回答
  •  猫巷女王i
    2020-12-01 13:31

    Suitable for Spring Boot or folks using OAuth

    @Profile("test")
    @EnableWebSecurity
    static class BasicWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable().authorizeRequests().anyRequest().anonymous().and().httpBasic().disable();
        }
    }
    

    If you are using @EnableOAuth2Client or @EnableResourceServer, then in test profile switch to basic auth and then disable the same. In Spring Boot,to switch off the spring security default configuration completely in a web application you need to add a bean with @EnableWebSecurity

提交回复
热议问题