程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> Windows下JBoss配置詳解

Windows下JBoss配置詳解

編輯:關於JAVA

JBoss配置

1.jmx-console 登錄的用戶名和密碼設置

默認情況訪問 http://localhost:8080/jmx-console 就可以浏覽jboss的部署管理的一些信息,不需要輸入用戶名和密碼,使用起來有點安全隱患。下面我們針對此問題對jboss進行配置,使得訪問jmx-console也必須要知道用戶名和密碼才可進去訪問。JBoss配置步驟如下:

1)找到JBoss安裝目錄/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml文件,去掉<security-domain>java:/jaas/jmx-console</security-domain>的注釋。修改後的該文件內容為:

<jboss-web>  
   <!-- Uncomment the security-domain to enable security. You will   
      need to edit the htmladaptor login configuration to setup the   
      login modules used to authentication users.-->  
      <security-domain>java:/jaas/jmx-console</security-domain>  
</jboss-web>

2)修改與i)中的jboss-web.xml同級目錄下的web.xml文件,查找到<security-constraint/>節點,去掉它的注釋,修改後該部分內容為:

<!-- A security constraint that restricts access to the HTML JMX console   
   to users with the role JBossAdmin. Edit the roles to what you want and   
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable   
   secured access to the HTML JMX console.-->  
   <security-constraint>  
     <web-resource-collection>  
       <web-resource-name>HtmlAdaptor</web-resource-name>  
       <description>An example security config that only allows users with the   
         role JBossAdmin to access the HTML JMX console web application   
       </description>  
       <url-pattern>/*</url-pattern>  
       <http-method>GET</http-method>  
       <http-method>POST</http-method>  
     </web-resource-collection>  
     <auth-constraint>  
       <role-name>JBossAdmin</role-name>  
     </auth-constraint>  
   </security-constraint>

3) 在第一步中的jmx-console安全域和第二步中的運行角色JBossAdmin都是在login-config.xml中配置,我們在JBoss安裝目錄/server/default/config下找到它,並進行JBoss配置。查找名字為:jmx-console的application-policy:

<application-policy name = "jmx-console">  
       <authentication>  
          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"  
             flag = "required">  
           <module-option name="usersProperties">props/jmx-console-users.properties</module-option>  
           <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option>  
          </login-module>  
       </authentication>  
    </application-policy>

在此處可以看出,登錄的角色、用戶等的信息分別在props目錄下的jmx-console-roles.properties和jmx-console-users.properties文件中設置,分別打開這兩個文件。

其中jmx-console-users.properties文件的內容如下:

# A sample users.properties file for use with the UsersRolesLoginModule
admin=admin

該文件定義的格式為:用戶名=密碼,在該文件中,默認定義了一個用戶名為admin,密碼也為admin的用戶,讀者可將其改成所需的用戶名和密碼。

jmx-console-roles.properties的內容如下:

# A sample roles.properties file for use with the UsersRolesLoginModule
admin=JBossAdmin, HttpInvoker

該文件定義的格式為:用戶名=角色,多個角色以“,”隔開,該文件默認為admin用戶定義了JBossAdmin和HttpInvoker這兩個角色。

配置完成後讀者可以通過訪問: http://localhost:8088/jmx-console/ ,輸入jmx-console-roles.properties文件中定義的用戶名和密碼,訪問jmx-console的頁面。

2.web-console 登錄的用戶名和密碼設置

默認情況下,用戶訪問JBoss的web-console時,不需要輸入用戶名和密碼,為了安全起見,我們通過修改配置來為其加上用戶名和密碼。步驟如下:

1)找到JBoss安裝目錄"server"default"deploy"management"console-mgr.sar"web-console.war"WEB-INF"jboss-web.xml文件,去掉<security-domain>java:/jaas/web-console</security-domain>的注釋,修改後的文件內容為:

<?xml version='1.0' encoding='UTF-8' ?>  
<!DOCTYPE jboss-web   
    PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"   
    "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">  
<jboss-web>  
   <!-- Uncomment the security-domain to enable security. You will   
   need to edit the htmladaptor login configuration to setup the   
   login modules used to authentication users.-->  
   <security-domain>java:/jaas/web-console</security-domain>  
   <!-- The war depends on the -->  
   <depends>jboss.admin:service=PluginManager</depends>  
</jboss-web>

2)打開1)中jboss-web.xml同目錄下的web.xml文件,去掉<security-constraint>部分的注釋,修改後的該部分內容為:

<!-- A security constraint that restricts access to the HTML JMX console   
   to users with the role JBossAdmin. Edit the roles to what you want and   
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable   
   secured access to the HTML JMX console.-->  
   <security-constraint>  
   <web-resource-collection>  
   <web-resource-name>HtmlAdaptor</web-resource-name>  
   <description>An example security config that only allows users with the   
   role JBossAdmin to access the HTML JMX console web application   
   </description>  
   <url-pattern>/*</url-pattern>  
   <http-method>GET</http-method>  
   <http-method>POST</http-method>  
   </web-resource-collection>  
   <auth-constraint>  
   <role-name>JBossAdmin</role-name>  
   </auth-constraint>  
   </security-constraint>

3)打開JBoss安裝目錄"server"default"conf下的login-config.xml文件,搜索web-console,可找到如下內容:

<application-policy name = "web-console">  
       <authentication>  
          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"  
             flag = "required">  
             <module-option name="usersProperties">web-console-users.properties</module-option>  
             <module-option name="rolesProperties">web-console-roles.properties</module-option>  
          </login-module>  
       </authentication>  
    </application-policy>

以上代碼就可以完成JBoss配置了。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved