赞
踩
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>Private</web-resource-name>
- <!-- 需要约束的请求路径-->
- <url-pattern>/private/*</url-pattern>
- <!-- 需要约束的请求方式-->
- <http-method>GET</http-method>
- </web-resource-collection>
- <!--用于指定可以访问该资源集合的用户角色-->
- <auth-constraint>
- <role-name>admin</role-name>
- </auth-constraint>
- <!--用来显示怎样保护在客户端和Web容器之间传递的数据-->
- <user-data-constraint>
- <!--
- ● NONE,这意味着应用不需要传输保证。
- ● INTEGRAL,意味着服务器和客户端之间的数据必须以某种方式发送,而且在传送中不能改变。
- ● CONFIDENTIAL,这意味着传输的数据必须是加密的数据。
- -->
- <transport-guarantee>NONE/INTEGRAL/CONFIDENTIAL</transport-guarantee>
- </user-data-constraint>
- </security-constraint>
以spring boot为例,因为spring boot中内嵌tomcat
- @Configuration
- public class SecurityConfig {
- @Bean
- public TomcatServletWebServerFactory servletContainer() {
- TomcatServletWebServerFactory tomcatServletContainerFactory = new TomcatServletWebServerFactory();
- tomcatServletContainerFactory.addContextCustomizers(new TomcatContextCustomizer() {
-
- @Override
- public void customize(Context context) {
- SecurityConstraint securityConstraint = new SecurityConstraint();
- SecurityCollection collection = new SecurityCollection();
- collection.addPattern("/admin/*");
- securityConstraint.addCollection(collection);
- securityConstraint.addAuthRole("admin");
- context.addConstraint(securityConstraint);
- }
- });
- return tomcatServletContainerFactory;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。