2015-09-29 13 views
1

我正在編寫管理webapp以部署在Wildfly上。 它將由有權訪問管理控制檯的相同用戶使用(http://localhost:9990/)。 如果我可以聲明我的應用程序應該在ManagementRealm中使用HTTP基本身份驗證,就像Console一樣,那將是非常好的選擇。Wildfly上的ManagementRealm中的web應用程序

天真,樂觀的嘗試沒有成功:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 
    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Admin Panel</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
    </security-constraint> 
    <login-config> 
     <auth-method>BASIC</auth-method> 
     <realm-name>ManagementRealm</realm-name> 
    </login-config> 
</web-app> 

這並不是在所有觸發HTTP基本登錄對話框。 有沒有簡單的方法將我的應用程序插入ManagementRealm?

回答

1

我發現我需要創建一個與ManagementRealm鏈接的安全域。配置分佈在三個地方:

1)一個新的安全域需要委託給ManagementRealm使用RealmDirect登錄模塊添加:

<subsystem xmlns="urn:jboss:domain:security:1.2"> 
    <security-domains> 
     .... 
     <security-domain name="management" cache-type="default"> 
      <authentication> 
       <login-module code="RealmDirect" flag="required"> 
        <module-option name="realm" value="ManagementRealm"/> 
       </login-module> 
      </authentication> 
     </security-domain> 

這可以通過jboss-cli做到:

/subsystem=security/security-domain=management:add(cache-type=default) 
/subsystem=security/security-domain=management/authentication=classic:add(\ 
    login-modules=[{\ 
     "code"=>"RealmDirect", "flag"=>"required", \ 
     "module-options"=>[("realm"=>"ManagementRealm")]\ 
    }]) 

2)該應用程序需要使用WEB-INF/jboss-web.xml引用此安全域:

<jboss-web> 
    <security-domain>management</security-domain> 
</jboss-web> 

3)是直截了當的web.xml開啓HTTP基本登錄對話框:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 
    <security-role> 
     <role-name>*</role-name> 
    </security-role> 
    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Admin Panel</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>*</role-name> 
     </auth-constraint> 
    </security-constraint> 
    <login-config> 
     <auth-method>BASIC</auth-method> 
     <realm-name>[message show in login dialog]</realm-name> 
    </login-config> 
</web-app> 
0

Wildfly不會遵循安全性約束,除非你將其綁定到一個安全角色:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 

    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Admin Panel</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>*</role-name> 
     </auth-constraint> 
    </security-constraint> 

    <login-config> 
     <auth-method>BASIC</auth-method> 
     <realm-name>ManagementRealm</realm-name> 
    </login-config> 

    <security-role> 
     <role-name>*</role-name> 
    </security-role> 
</web-app> 

這將使基本身份驗證負載但你必須在那裏ManagementRealm只綁定到管理端口的問題在你的standalone.xml中,所以你將不得不改變它。您可能需要刪除ApplicationRealm,以免發生衝突。

<management-interfaces> 
     <http-interface security-realm="ManagementRealm" http-upgrade-enabled="true"> 
      <socket-binding http="management-http"/> 
     </http-interface> 
    </management-interfaces> 
相關問題