我有一个简单的spring启动应用程序与SSL和x509客户端证书的spring安全。
我想只使用http而不使用客户端证书在dev-mode下运行它。以及使用https和x509证书的prod-mode。
我有一个简单的演示应用程序,运行安全的网站OK。https://coling01@bitbucket.org/coling01/ssldemo.git
使用证书访问安全站点工作正常a) curl --cacert server.pem --cert client1.p12:changeit https://localhost:8443/demo
我希望能够切换到不安全模式,并在没有证书的情况下在port80上使用b) http (我确实有8080端口在运行,它会响应,但在尝试检查未通过的客户端证书时遇到错误)
有什么想法吗?我希望有一个简单的开关来禁用client-auth,但是找不到它。
发布于 2017-03-27 20:26:16
按照Mkyong's example使用Spring Profiles。这样你就可以创建两个不同的WebSecurityConfigurerAdapter,
第一个是dev配置文件:
@Profile("dev")
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class DevSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().permitAll();
}
}和第二个产品准备就绪并确保安全:
@Profile("prod")
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ProductionSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(userDetailsService());
}
}希望这能有所帮助!
https://stackoverflow.com/questions/43027126
复制相似问题