默認(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)。步驟如下:
i) 找到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>
ii)修改與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>
在此處可以看出,為登錄配置了角色JBossAdmin。
iii) 在第一步中的jmx-console安全域和第二步中的運(yùn)行角色JBossAdmin都是在login-config.xml中配置,我們?cè)贘Boss安 裝目錄/server/default/conf下找到它。查找名字為: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è)置,分別打開這兩個(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è)角色以“,”隔開,該文件默認(rèn)為admin用戶定義了JBossAdmin和HttpInvoker這兩個(gè)角色。
配置完成后讀者可以通過(guò)訪問(wèn): http://localhost:8088/jmx-console/ ,輸入jmx-console-roles.properties文件中定義的用戶名和密碼,訪問(wèn)jmx-console的頁(yè)面。