我一直在尝试根据以下链接来获取CLIENT-CERT领域身份验证:
但是,尽管使用了以下命令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-pattern?
替代问题
如果可以使Spring Boot中的嵌入式Tomcat使用web.xml,该怎么做?
编辑:实际上,考虑到我正在尝试使用CLIENT-CERT auth方法,这可能是httpSecurity.x509()
样本更少的示例……我迷路了。
这是一个在容器级别使用基于证书的身份验证的示例:https : //github.com/SpringOne2GX-2014/microservice-security/tree/master/certs(更多的是关于server.xml中存在的内容而不是Web中的内容。 xml(非嵌入式容器中)。该应用程序是安全的。如果添加WebSecurityConfigurationAdapter
和进行调用,http.x509()
您还将获得经过身份验证的主体,并将其转换为,Authentication
并在Spring Security的常规位置可用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句