簡體   English   中英

如何在Jboss eap 6.1.0中的特定URL上設置身份驗證

[英]How to set authentication on a specific URL in Jboss eap 6.1.0

我正在一個項目中,我想在此項目上對特定的URL進行身份驗證。 Jboss版本:Jboss eap 6.1.0

我的應用程序中有一個URL http:// localhost:8080 / myApp / monitoring,當用戶點擊該URL時,它會詢問用戶ID和密碼

以下是我已經完成的步驟

在WEB.XML中添加以下內容

<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

<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

任何人都可以幫忙。 提前致謝。

您已在web.xml錯誤配置了security-constraint元素。

嘗試使用以下值:

<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命名它們(否則僅保護命名的方法)
  • 如果您指定transport-guarantee (值不等於NONE ),那么實際上您使用的是https (SSL / TLS)而不是http請求。
  • 如果您不想向所有人授予訪問權限,則必須提供auth-constraint (以及您授予訪問權限的角色列表)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM