【发布时间】:2016-07-25 04:27:57
【问题描述】:
我想在我的应用程序中禁用 Spring Security,并在 application.yml 文件中设置属性 security.basic.enable=false。
security:
basic:
enabled: false
我使用 spring-boot-actuator 检查了 /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);}
}
这是安全配置:
@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");
}
}
【问题讨论】:
-
谢谢,我尝试设置属性 security.ignored=/** 并成功。有一个类似的问题stackoverflow.com/questions/36280181/…
标签: java spring spring-mvc spring-security spring-boot