---
title: "Jboss下jmx-console与web-console配置"
author: "wode66"
date: "2011-10-09T11:12:30Z"
tags: []
categories: ["操作系统"]
slug: "jboss-jmx-console-web-console"
draft: false
lastmod: "2011-10-09T11:12:30Z"
id: 1187517
url: "https://suo.iteye.com/blog/1187517"
---

*JBoss安装成功后，一般可以通过http://localhost:port来访问.Jmx Console和Jboss Web Console 里面可以修改和删除应用的参数，如果不加强安全设置，将会带来严重安全后果。*   
*默认登录jmx-console的账号信息是：admin/admin，因此我们应该修改这个账号信息。* 

**一、JMX安全配置**   
1： 找到%JBOSS\_HOME%/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml文件，去掉对下面这段xml文本的注释。 

Xml代码 

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

1. &lt;jboss-web&gt;
2. &lt;security-domain&gt;java:/jaas/jmx-console&lt;/security-domain&gt;
3. &lt;/jboss-web&gt;

      
2： 与jboss-web.xml同级目录下还有一个文件web.xml，找到下面这段xml文本，取消注释。 

Xml代码 

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

01. &lt;security-constraint&gt;
02. &lt;web-resource-collection&gt;
03. &lt;web-resource-name&gt;HtmlAdaptor&lt;/web-resource-name&gt;
04. &lt;description&gt;An example security config that only allows users with the
05. role JBossAdmin to access the HTML JMX console web application
06. &lt;/description&gt;
07. &lt;url-pattern&gt;/\*&lt;/url-pattern&gt;
08. &lt;http-method&gt;GET&lt;/http-method&gt;
09. &lt;http-method&gt;POST&lt;/http-method&gt;
10. &lt;/web-resource-collection&gt;
11. &lt;auth-constraint&gt;
12. &lt;role-name&gt;JBossAdmin&lt;/role-name&gt;
13. &lt;/auth-constraint&gt;
14. &lt;/security-constraint&gt;

注意：&lt;role-name&gt;JBossAdmin&lt;/role-name&gt;   
引用了一个已定义的角色名:JBossAdmin(这个角色名称是在该文件下的&lt;security-role&gt;&lt;role-name&gt;JBossAdmin&lt;/role-name&gt;&lt;/security-role&gt;节点中定义的),   
jmx-console-roles.properties文件中的角色名称必须与其一致,   
如：duqiang=JBossAdmin,HttpInvoker;定义了一个duqiang用户,其属于JBossAdmin角色 

3： 在第一步中的jmx-console安全域和第二步中的运行角色JBossAdmin与用户名和密码都是在login-config.xml中配置，   
我们在%JBOSS\_HOME%/server/default/conf/login-config.xml文件可以看到以下配置， 

Xml代码 

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

01. &lt;!--此处应与jboss-web.xml文件中的&lt;security-domain&gt;java:/jaas/jmx-console&lt;/security-domain&gt; 一致 --&gt;
02. &lt;application-policy name = "jmx-console"&gt;
03. &lt;authentication&gt;
04. &lt;login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
05. flag = "required"&gt;
06. &lt;module-option name="usersProperties"&gt;props/jmx-console-users.properties&lt;/module-option&gt;
07. &lt;module-option name="rolesProperties"&gt;props/jmx-console-roles.properties&lt;/module-option&gt;
08. &lt;/login-module&gt;
09. &lt;/authentication&gt;
10. &lt;/application-policy&gt;

文件props/jmx-console-users.properties中定义了用户名、密码；文件props/jmx-console-roles.properties中定义了用户所属角色   
注：   
jmx-console-users.properties 格式是：用户名=密码明文   
jmx-console-roles.properties 格式是：用户名=角色1,角色2,角色3 

可以找到这两个文件，修改用户名和密码。 

**二、WEB-CONSOLE的安全配置**   
1：   
找到%JBOSS\_HOME%/server/default/deploy/ management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml文件，去掉对以下xml文本的注释。 

Xml代码      
&lt;jboss-web&gt;   
&lt;depends&gt;jboss.admin:service=PluginManager&lt;/depends&gt;   
&lt;/jboss-web&gt;   
2：   
与jboss-web.xml同级目录下还有一个文件web.xml，找到下面这段xml文本，取消注释。 

Xml代码 

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

01. &lt;security-constraint&gt;
02. &lt;web-resource-collection&gt;
03. &lt;web-resource-name&gt;HtmlAdaptor&lt;/web-resource-name&gt;
04. &lt;description&gt;An example security config that only allows users with the
05. role JBossAdmin to access the HTML JMX console web application
06. &lt;/description&gt;
07. &lt;url-pattern&gt;/\*&lt;/url-pattern&gt;
08. &lt;http-method&gt;GET&lt;/http-method&gt;
09. &lt;http-method&gt;POST&lt;/http-method&gt;
10. &lt;/web-resource-collection&gt;
11. &lt;auth-constraint&gt;
12. &lt;role-name&gt;JBossAdmin&lt;/role-name&gt;
13. &lt;/auth-constraint&gt;
14. &lt;/security-constraint&gt;

3：在 %JBOSS\_HOME%/server/default/deploy/management/console-mgr.sar/web-console.war/WEB-INF/classes目录下找到web-console-users.properties,web-console-roles.properties文件   
分别把他们重命名成users.properties与roles.properties。   
4:在% JBOSS\_HOME%/server/default/conf/login-config.xml文件可以看到以下配置：   
Xml代码    

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

1. &lt;application-policy name = "web-console"&gt;
2. &lt;authentication&gt;
3. &lt;login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
4. flag = "required"&gt;
5. &lt;module-option name="usersProperties"&gt;web-console-users.properties&lt;/module-option&gt;
6. &lt;module-option name="rolesProperties"&gt;web-console-roles.properties&lt;/module-option&gt;
7. &lt;/login-module&gt;
8. &lt;/authentication&gt;
9. &lt;/application-policy&gt;

修改该配置为： 

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

1. &lt;application-policy name = "web-console"&gt;
2. &lt;authentication&gt;
3. &lt;login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
4. flag = "required"&gt;
5. &lt;module-option name="usersProperties"&gt;users.properties&lt;/module-option&gt;
6. &lt;module-option name="rolesProperties"&gt;roles.properties&lt;/module-option&gt;
7. &lt;/login-module&gt;
8. &lt;/authentication&gt;
9. &lt;/application-policy&gt;

你可以修改users.properties其中的用户名和密码，格式和上面的两个properties文件中的一样。 

启动服务输入http://localhost:8080/jmx-console 和http://localhost:8080/web-console测试安全机制,安是否和你自己修改后的账号信息一致。   
也可以启动服务输入http://localhost:8080/   
然后分别点击JMX Console以及Jboss Web Console测试安全机制。 

*注意：如果在配置web-console时，不对web-console-users.properties与web-console-roles.properties文件重命名和修改login-config.xml文件中的&lt;module-option name="usersProperties"&gt;users.properties&lt;/module-option&gt;*   
*&lt;module-option name="rolesProperties"&gt;roles.properties&lt;/module-option&gt; 节点内容时，控制台会抛出异常信息。如下：* 

Java代码  [![收藏代码](http://duqiangcise.iteye.com/images/icon_star.png)](http://duqiangcise.iteye.com/blog/780450 "收藏这段代码")

1. Failed to load users/passwords/role files
2. java.io.IOException: No properties file: users.properties or defaults: defaultUsers.properties found