【发布时间】:2013-07-15 12:14:23
【问题描述】:
在研究 servlet 中的安全约束和过滤器时,我在 web.xml 文件中做了以下声明,但没有按预期工作:
<security-constraint>
<web-resource-collection>
<web-resource-name>BeerSelector</web-resource-name>
<url-pattern>/SelectBeer.do</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>model.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/SelectBeer.do</url-pattern>
</filter-mapping>
根据我的阅读:过滤器应该在请求到达某个url之前遇到,那么,为什么首先调用security-constraint?
我知道从安全角度来看这是有道理的(要到达您必须经过身份验证的过滤器),但我想知道请求触发的序列。
容器是否首先搜索受保护的资源,从而触发安全约束?
但这将与下面从 Head First Servlets 和 Jsp 中引用的段落相矛盾“
请记住,在 DD 中, 发生在请求之后。换句话说,客户已经做出 Container 开始查看时的请求 元素来决定如何响应。请求 数据已经通过网络发送了
或者请求可能同时触发:过滤器和安全约束,但安全约束优于过滤器?
【问题讨论】:
标签: java servlets servlet-filters security-constraint