我希望在我的应用程序中禁用spring安全性,并在security.basic.enable=false文件中设置属性application.yml。
security:
basic:
enabled: false
我使用弹簧引导驱动器检查了/env,并发现它已正确加载:(在第2行)
[classpath:/application.yml]":{"spring.datasource.url":"jdbc:mysql://localhost:3306/toe?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true","spring.datasource.username":"root","spring.datasource.password":"******",
"security.basic.enabled":false,
"server.port":7777,"flyway.enabled":false}}
但是,安全配置仍然有效,我无法访问需要身份验证的配置,但我可以访问那些是permitAll。
这是应用程序类:
@SpringBootApplication
@MapperScan("team.xuli.toe.dao")
public class ToeServerApplication {
public static void main(String[] args) {
SpringApplication.run(ToeServerApplication.class, args);}
}
这是securityConfigutaion:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.httpBasic();
http.
authorizeRequests()
.antMatchers("/hello").permitAll()
.anyRequest().authenticated();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
System.out.println("user added in mem!");
auth
.inMemoryAuthentication()
.withUser("xqf").password("123").roles("ADMIN");
}
}
发布于 2016-04-05 15:14:44
如果您在应用程序中的任何位置使用@Configuration
定义@EnableWebSecurity
,它将在Spring中关闭默认的webapp安全设置。
发布于 2016-04-05 09:56:05
如果您需要将安全性作为依赖项,但不希望Spring为您配置安全性,则可以使用此排除:
@EnableAutoConfiguration(exclude = {
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class
})
https://stackoverflow.com/questions/36422837
复制相似问题