我只想用路径/rest/*限制GET请求的域。所以我在我的web.xml中声明:
<security-constraint>
<web-resource-collection>
<web-resource-name>All</web-resource-name>
<url-pattern>/rest/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Auth</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>但是,当对(例如) '/rest/add‘执行POST请求时,when容器接受并提交POST请求。为什么会这样呢?
发布于 2012-08-01 16:26:41
这是因为第一个安全约束被第二个安全约束覆盖(顺序很重要),第二个约束没有http-method (如果在web-resource-collection中没有HTTP -method元素,这意味着所有HTTP方法都是允许的)。
这意味着这段代码
<security-constraint>
<web-resource-collection>
<web-resource-name>All</web-resource-name>
<url-pattern>/rest/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
</security-constraint>是没用的
发布于 2015-01-19 02:22:51
安全约束不会被覆盖。如果不同约束的url模式是相同的,则它们是相加的。在上面的例子中,url模式是不同的,所以第一个赢得并允许发布。
https://stackoverflow.com/questions/11755014
复制相似问题