tomcat对于web.xml的security-constraint使用的处理机制
知识点
web.xml中<security-constraint> 的子元素 <http-method> 是可选的,如果没有 <http-method> 元素,这表示将禁止所有 HTTP 方法访问相应的资源。
子元素 <auth-constraint> 需要和 <login-config> 相配合使用,但可以被单独使用。如果没有 <auth-constraint> 子元素,这表明任何身份的用户都可以访问相应的资源。也就是说,如果 <security-constraint> 中没有 <auth-constraint> 子元素的话,配置实际上是不起中用的。如果加入了 <auth-constraint> 子元素,但是其内容为空,这表示所有身份的用户都被禁止访问相应的资源。
问题
对于同一个url-pattern,在web.xml出现2个<security-constraint>,一个是对该url-pattern进行了role的限制,一个没有限制role,会如何?
实践
一个是对该url-pattern进行了role的限制,即配置auth-constraint
如:
<security-constraint><web-resource-collection><web-resource-name>test2</web-resource-name><url-pattern>/*</url-pattern></web-resource-collection><auth-constraint><role-name>tomcat1</role-name></auth-constraint></security-constraint>
一个是对该url-pattern没有进行role的限制
如:
<security-constraint><web-resource-collection><web-resource-name>test3</web-resource-name><url-pattern>/*</url-pattern></web-resource-collection></security-constraint>
对于tomcat而言,在org.apache.catalina.authenticator.AuthenticatorBase认证类中
/*** Enforce the security restrictions in the web application deployment* descriptor of our associated Context.** @param request Request to be processed* @param response Response to be processed** @exception IOException if an input/output error occurs* @exception ServletException if thrown by a processing element*/@Overridepublic void invoke(Request request, Response response)throws IOException, ServletException {....// Since authenticate modifies the response on failure,// we have to check for allow-from-all first.//boolean authRequired;if (constraints == null) {authRequired = false;} else {//有安全限制authRequired = true;for(i=0; i < constraints.length && authRequired; i++) {if(!constraints[i].getAuthConstraint()) {//如果不需要认证限制authRequired = false;//则不需要认证} else if(!constraints[i].getAllRoles()) {//如果不是*,即所有角色的话String [] roles = constraints[i].findAuthRoles();if(roles == null || roles.length == 0) { //只要此url-pattern有一个限制没有控制角色,则满足次url-pattern的url可以被任意角色和匿名用户访问authRequired = false;//则不需要认证}}}} ......
结论
所以按照上面同时配置同一个url-pattern,不同安全限制,只要有一个不限制角色,则此url-pattern不受角色限制,满足次url-pattern的url可以被任意角色和匿名用户访问
转载于:https://www.cnblogs.com/yangjun1120/archive/2012/11/22/2782322.html
tomcat对于web.xml的security-constraint使用的处理机制相关推荐
- Tomcat中web.xml文件的详细说明
Tomcat中web.xml文件的详细说明 <?xml version="1.0" encoding="GB2312"?> <!-- We ...
- tomcat web.xml配置
tomcat 禁用不安全的http请求方式(转) 1:我的配置 web.xml(url下禁用的请求方式) <security-constraint> <web-resource ...
- 嵌入式tomcat的不使用web.xml原理分析
前言 前面的章节讲了嵌入式tomcat使用web.xml启动,这章说说不使用web.xml启动tomcat.有了这个就明白Spring Boot是如何在没有web.xml的的情况下实现web能力的,以 ...
- Tomcat原理系列之四:Tomat如何启动spring(加载web.xml)
Tomcat原理系列之四:Tomat如何启动spring 熟悉的web.xml ContextLoaderListener Tomcat的初始化StandardContext.startInterna ...
- web.xml配置的详细说明
web.xml配置的详细说明 (转载)[TOMCAT]用web.xml控制Web应用的行为 1 定义头和根元素 部署描述符文件就像所有XML文件一样,必须以一个XML头开始.这个头声明可以使用的XML ...
- Tomcat之Web 应用配置
目录 1 .ServletContext 初始化参数 2 .会话配置 3. Servlet配置 4 .Listener配置 5.Filter配置 6 . ...
- web.xml中url-pattern的配置详解
前言 今天研究了一下tomcat上web.xml配置文件中url-pattern的问题. 这个问题其实毕业前就困扰着我,当时忙于找工作. 找到工作之后一直忙,也就没时间顾虑这个问题了. 说到底还是自己 ...
- 在tomcat下部署两个或多个项目时 log4j和web.xml配置webAppRootKey 的问题(转)
在tomcat下部署两个或多个项目时 web.xml文件中最好定义webAppRootKey参数,如果不定义,将会缺省为"webapp.root",如下: <!-- 应用路径 ...
- Tomcat web.xml配置参数详解
Apache Tomcat Configuration Reference - The Context Container https://tomcat.apache.org/tomcat-5.5-d ...
最新文章
- MATLAB实时标定
- JavaScript学习笔记——对象知识点
- redis数据持久化的两种方式
- concat函数java_MySql中CONCAT(str1,str2,...)函数
- 埋点套路深,千万别掉“坑”
- 看国外女神级程序员,直播写代码一年的感悟
- python:栈的理解与应用,让你快速入门Python
- vscode中安装webpack_leaflet-webpack 入门开发系列一初探篇(附源码下载)
- sql语句count_带COUNT()函数SQL SELECT语句
- [bzoj3670] [NOI2014] [lg2375] 动物园
- DOS批处理命令之for命令(批量安装APK)
- 2015款java 650b duina_整车推荐:9款5000元级别热销山地车
- 2019新个税如何计算
- Android 字体库的使用-引入外部字体
- 查看英伟达Nvidia显卡、cuda版本
- 贵金属交易最佳时间,2023伦敦金交易平台最新排行榜
- 2012年度十大杰出IT博客之 蒋金楠
- linux修复笔记本电池电量,我戴尔笔记本电池损耗到百分之三十了!怎么修好啊!晕...
- 芋道 Spring Boot 对象转换 MapStruct 入门
- shell脚本一键安装lnmp