在这种情况下,我需要拒绝访问未使用的HTTP方法。
我们在JBoss 4.2上运行,需要登录。除get和POST之外,应拒绝所有其他获取访问权限的尝试。
我尝试了web.xml的以下配置,但没有任何帮助。servlet仍然被调用,并返回例如。在DELETE请求上出现“拒绝访问”。‘
相反,我希望返回一个501: Not implemented。
如果我在第一个安全约束中没有包含任何HTTP方法,那么用户会立即得到一个未经授权的页面。
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Deny most when not logged in</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<!-- no auth-constraint tag here -->
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Allow methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
</web-app>有什么办法可以做到这一点?
发布于 2014-04-11 03:14:55
通过尝试不同的可能性和Postman,我发现第一个安全约束是黑名单。此处添加的http方法是那些被拒绝的方法,并且JBoss返回403。
因此,第一个安全约束现在如下所示:
<security-constraint>
<web-resource-collection>
<web-resource-name>Deny most when not logged in</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint/>
</security-constraint>https://stackoverflow.com/questions/22994358
复制相似问题