Windows下JBoss配置詳解
JBoss配置
1.jmx-console 登錄的用戶名和密碼設(shè)置
默認(rèn)情況訪問(wèn) http://localhost:8080/jmx-console 就可以瀏覽jboss的部署管理的一些信息,不需要輸入用戶名和密碼,使用起來(lái)有點(diǎn)安全隱患。下面我們針對(duì)此問(wèn)題對(duì)jboss進(jìn)行配置,使得訪問(wèn)jmx-console也必須要知道用戶名和密碼才可進(jìn)去訪問(wèn)。JBoss配置步驟如下:
1)找到JBoss安裝目錄/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml文件,去掉<security-domain>java:/jaas/jmx-console</security-domain>的注釋。修改后的該文件內(nèi)容為:
- <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同級(jí)目錄下的web.xml文件,查找到<security-constraint/>節(jié)點(diǎn),去掉它的注釋,修改后該部分內(nèi)容為:
- <!-- 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安全域和第二步中的運(yùn)行角色JBossAdmin都是在login-config.xml中配置,我們?cè)贘Boss安裝目錄/server/default/config下找到它,并進(jìn)行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文件中設(shè)置,分別打開(kāi)這兩個(gè)文件。
其中jmx-console-users.properties文件的內(nèi)容如下:
# A sample users.properties file for use with the UsersRolesLoginModule
admin=admin
該文件定義的格式為:用戶名=密碼,在該文件中,默認(rèn)定義了一個(gè)用戶名為admin,密碼也為admin的用戶,讀者可將其改成所需的用戶名和密碼。
jmx-console-roles.properties的內(nèi)容如下:
# A sample roles.properties file for use with the UsersRolesLoginModule
admin=JBossAdmin, HttpInvoker
該文件定義的格式為:用戶名=角色,多個(gè)角色以“,”隔開(kāi),該文件默認(rèn)為admin用戶定義了JBossAdmin和HttpInvoker這兩個(gè)角色。
配置完成后讀者可以通過(guò)訪問(wèn): http://localhost:8088/jmx-console/ ,輸入jmx-console-roles.properties文件中定義的用戶名和密碼,訪問(wèn)jmx-console的頁(yè)面。
2.web-console 登錄的用戶名和密碼設(shè)置
默認(rèn)情況下,用戶訪問(wèn)JBoss的web-console時(shí),不需要輸入用戶名和密碼,為了安全起見(jiàn),我們通過(guò)修改配置來(lái)為其加上用戶名和密碼。步驟如下:
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>的注釋,修改后的文件內(nèi)容為:
- <?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)打開(kāi)1)中jboss-web.xml同目錄下的web.xml文件,去掉<security-constraint>部分的注釋,修改后的該部分內(nèi)容為:
- <!-- 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)打開(kāi)JBoss安裝目錄"server"default"conf下的login-config.xml文件,搜索web-console,可找到如下內(nèi)容:
- <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配置了。
【編輯推薦】