首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Jboss 6.1.0中设置特定URL的身份验证

如何在Jboss 6.1.0中设置特定URL的身份验证
EN

Stack Overflow用户
提问于 2015-11-29 16:21:17
回答 1查看 536关注 0票数 0

我正在做一个项目,我想在特定的url上应用身份验证。Jboss版本: Jboss 6.1.0

在我的应用程序http://localhost:8080/myApp/monitoring中有一个url,当用户点击这个URL时,它会询问用户id和密码。

以下是我所做的步骤

在WEB.XML中添加以下内容

代码语言:javascript
复制
<security-constraint>
    <web-resource-collection>
        <web-resource-name>All Access</web-resource-name>
        <url-pattern>/monitoring</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>ApplicationRealm</realm-name>
</login-config>

<security-role>
    <role-name>user</role-name>
</security-role>

jboss-web.xml

代码语言:javascript
复制
<jboss-web>
    <security-domain>java:/jaas/other</security-domain>
</jboss-web>

然后使用add-user.bat文件添加用户。但是当我点击url时,http://localhost:8080/myApp/monitoring服务器将返回错误代码302,并且url将重定向到https://localhost/myApp/monitoring

有人能帮忙吗。提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-01 07:56:28

您在security-constraint中错误配置了web.xml元素。

尝试使用以下值:

代码语言:javascript
复制
<security-constraint>
    <web-resource-collection>
        <web-resource-name>All Access</web-resource-name>
        <url-pattern>/monitoring</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>

和现在的一些细节:

  • 如果要保护访问给定URL的所有HTTP方法,请不要在web-resource-collection中给它们命名(否则只有命名的方法受到保护)
  • 如果您指定了https (值不等于NONE),那么实际上的请求使用http (SSL/TLS)代替http
  • 如果不想向每个人授予访问权限,则必须提供auth-constraint (提供授予访问权限的角色列表)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33985004

复制
相关文章

相似问题

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