我一直在尝试基于以下链接使CLIENT-CERT领域身份验证工作:
http://twoguysarguing.wordpress.com/2009/11/03/mutual-authentication-with-client-cert-tomcat-6-and-httpclient/
然而,尽管使用了以下web.xml
,
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Demo App</web-resource-name>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>secureconn</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Demo App</realm-name>
</login-config>
<security-role>
<role-name>secureconn</role-name>
</security-role>
</web-app>
为了让HTTPS正常工作,我使用了以下链接:
http://thoughtfulsoftware.wordpress.com/2014/01/05/setting-up-https-for-spring-boot/
因此,我有了这样的东西:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.addContextCustomizers((TomcatContextCustomizer) customizer ->
{
//this is empty at the moment
});
factory.addConnectorCustomizers((TomcatConnectorCustomizer) (Connector con) -> {
//...configuration
});
return factory;
我也有这个来启用Spring Security:
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//...some configuration from the sample at https://spring.io/guides/gs/securing-web/
}
...
}
在我看来,嵌入式Tomcat并不真正关心web.xml
内容,所以我想我需要从Java配置它,可能使用Context Customizer
。我没有找到任何关于做这件事的资源,而且大多数参数都是String,所以我猜我要么做了一些非常错误的事情,要么只是没有文档记录,要么我看错了地方。
所以我的问题是,
http://java.boot.by/wcd-guide/ch05s03.html
如果不使用web.xml,那么应该如何使用Spring Boot指定领域、安全约束和登录配置/身份验证方法/url模式
备选问题,
如果可以让Spring Boot中的嵌入式Tomcat使用web.xml,那是如何做到的
编辑:事实上,考虑到我正在尝试使用CLIENT-CERT身份验证方法,这可能是httpSecurity.x509()
,它的样本更少。。。我迷路了。
以下是在容器级别使用基于证书的身份验证的示例:https://github.com/SpringOne2GX-2014/microservice-security/tree/master/certs(与非嵌入式容器中的web.xml相比,它更多地是关于server.xml中的内容)。该应用程序是安全的。如果添加一个WebSecurityConfigurationAdapter
并调用http.x509()
,那么经过身份验证的主体也将变成Authentication
,并在Spring Security的常见位置可用。