ITeye博客

Jboss中的web-console与jmx-console的配置

duqiangcise · 2010-10-10 15:34 · java · 企业架构 · Markdown

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代码

<jboss-web>    
<security-domain>java:/jaas/jmx-console</security-domain>    
</jboss-web>

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

Xml代码

<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 引用了一个已定义的角色名:JBossAdmin(这个角色名称是在该文件下的JBossAdmin节点中定义的), 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代码

<!--此处应与jboss-web.xml文件中的<security-domain>java:/jaas/jmx-console</security-domain> 一致 -->
<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-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代码
jboss.admin:service=PluginManager 2: 与jboss-web.xml同级目录下还有一个文件web.xml,找到下面这段xml文本,取消注释。

Xml代码

<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_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代码

<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> 

修改该配置为:

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

你可以修改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文件中的users.properties roles.properties 节点内容时,控制台会抛出异常信息。如下:

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

评论(1)

  1. #1 楼 · MyPointOne · 2014-03-18 08:55

    后面的异常为什么出现?好像没说清楚!

评论功能维护中,当前仅展示历史评论。