【发布时间】:2014-09-09 18:23:39
【问题描述】:
我认为,我有一个非常简单和基本的设置,用于在本地运行带有一些身份验证的 Spring Boot webapp。
我希望当我通过 Spring Boot 运行这个应用程序时,当我指定 local 配置文件时,我的自定义安全设置将覆盖默认行为。
mvn -Dspring.profiles.active="local" spring-boot:run
也许我指定了profiles.active 错误,但是当应用程序运行时,它仍然会吐出一个生成的密码来使用,并且似乎不允许在没有所述身份验证的情况下访问/login 路径。
我也没有看到/env 下的活动个人资料,这可能有点说明问题。
我有一个 WebSecurityConfigurer 像这样被覆盖:
@Configuration
@EnableWebSecurity
@Profile("local")
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin().permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN", "USER")
.and().withUser("user").password("user").roles("USER");
}
}
我的主要 @Configuration 类是您的标准 Spring Java 风格的基本配置:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
【问题讨论】:
标签: java spring spring-mvc spring-security spring-boot