一.知识点
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 */ @Override public 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可以被任意角色和匿名用户访问。
相关推荐
部署描述文件web.xml详解(web-app_2_3.dtd),全面介绍: 1. icon元素 2. display-name元素 3. description元素 4. distributable元素 5. context-param元素 6. filter元素 7. filter-mapping元素 8. ...
7-Constraint Satisfaction Problems.ppt 7-Logical Agents.ppt 8-First-Order Logic.ppt 9-Inference in first-order logic.key 9-Inference in first-order logic.ppt 10-Knowledge Representation.ppt 13-...
本文档介绍在大规模图数据库中计算标签可达性约束的查询问题。
在web.xml文件中配置下面一段内容 <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <http-method>HEAD...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
stylelint-z-index-value-constraint 用于设置z索引的最小和最大约束值的Stylelint规则。 这是插件的分支。 安装 npm install stylelint-z-index-value-constraint --save-dev 或者 yarn add stylelint-z-index-...
Machine Learning projects our ultimate desire to understand the essence of human intelligence onto the space of technology. As such, while it cannot be fully understood in the restricted field of ...
ORACLE OSB开发指南,英文版。 目录: Part I IDE Help for Oracle Service Bus 1 Introduction to Oracle Service Bus 2 Tasks Working with Projects, Folders, Resources, and Configurations .....................
A survey on shape-constraint deep learning for medical image segmentation.zip
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
利用Python+Gurobi编写代码,复现文章:Solving two-stage robust optimization problems using a column-and- constraint generation method。
Tomcat压缩包 资源下载,tomcat自带了一套管理程序...无论是basic还是digest,设置过程基本一致,在conf/server.xml中添加realm数据源,在{project}/WEB-INF/web.xml中添加 security-constraint 和 login-config属性。
This two-volume book shows ... a NodeJS-based back-end component for managing persistent storage and taking care of certain parts of the application logic (including constraint- based data validation).
stylelint-number-z-index-constraint 用于设置z索引的最小和最大约束值的Stylelint规则。 安装 npm install stylelint-number-z-index-constraint --save-dev 用法 将此配置添加到您的.stylelintrc : { " ...
Failed to resolve: com.android.support.constraint:constraint-layout:1.0.0-alpha1
SA0033413 - Schema Compare for SQL Server: system generated constraint names may distort schema compare results. SA0033483 - Task Manager and Query Execution dialogs/panes don't refresh task progress...
HibernateValidatorJSR303的参考实现使用指南.pdf JSR 303 的参考实现 使用指南 由 Hardy Ferentschik和Gunnar Morling and thanks to Shaozhuang Liu 4.3.1.Final 版权 © 2009 - 2011 Red Hat, Inc. & Gunnar ...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
ASN.1的正式标准文档和它的编码规则由 International Telecommunications Union Telecommunications Sector (ITU-T)和International Standards Organization (ISO) / International Electrotechnical Commission ...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...