首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拒绝访问j2ee中的HTTP方法

拒绝访问j2ee中的HTTP方法
EN

Stack Overflow用户
提问于 2014-04-11 00:57:20
回答 1查看 99关注 0票数 0

在这种情况下,我需要拒绝访问未使用的HTTP方法。

我们在JBoss 4.2上运行,需要登录。除get和POST之外,应拒绝所有其他获取访问权限的尝试。

我尝试了web.xml的以下配置,但没有任何帮助。servlet仍然被调用,并返回例如。在DELETE请求上出现“拒绝访问”。‘

相反,我希望返回一个501: Not implemented

如果我在第一个安全约束中没有包含任何HTTP方法,那么用户会立即得到一个未经授权的页面。

代码语言:javascript
复制
<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>

有什么办法可以做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2014-04-11 03:14:55

通过尝试不同的可能性和Postman,我发现第一个安全约束是黑名单。此处添加的http方法是那些被拒绝的方法,并且JBoss返回403。

因此,第一个安全约束现在如下所示:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22994358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档