日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tomcat对于web.xml的security-constraint使用的处理机制

發布時間:2023/12/9 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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使用的处理机制的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。