ITeye博客

Jboss下jmx-console与web-console配置

wode66 · 2011-10-09 11:12 · 操作系统 · 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代码 

Java代码  收藏代码

  1. <jboss-web>
  2. <security-domain>java:/jaas/jmx-console</security-domain>
  3. </jboss-web>

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

Xml代码 

Java代码  收藏代码

  1. <security-constraint>
  2. <web-resource-collection>
  3. <web-resource-name>HtmlAdaptor</web-resource-name>
  4. <description>An example security config that only allows users with the
  5. role JBossAdmin to access the HTML JMX console web application
  6. </description>
  7. <url-pattern>/*</url-pattern>
  8. <http-method>GET</http-method>
  9. <http-method>POST</http-method>
  10. </web-resource-collection>
  11. <auth-constraint>
  12. <role-name>JBossAdmin</role-name>
  13. </auth-constraint>
  14. </security-constraint>

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

  1. <!--此处应与jboss-web.xml文件中的<security-domain>java:/jaas/jmx-console</security-domain> 一致 -->
  2. <application-policy name = "jmx-console">
  3. <authentication>
  4. <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
  5. flag = "required">
  6. <module-option name="usersProperties">props/jmx-console-users.properties</module-option>
  7. <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option>
  8. </login-module>
  9. </authentication>
  10. </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-web> 
<depends>jboss.admin:service=PluginManager</depends> 
</jboss-web> 
2: 
与jboss-web.xml同级目录下还有一个文件web.xml,找到下面这段xml文本,取消注释。 

Xml代码 

Java代码  收藏代码

  1. <security-constraint>
  2. <web-resource-collection>
  3. <web-resource-name>HtmlAdaptor</web-resource-name>
  4. <description>An example security config that only allows users with the
  5. role JBossAdmin to access the HTML JMX console web application
  6. </description>
  7. <url-pattern>/*</url-pattern>
  8. <http-method>GET</http-method>
  9. <http-method>POST</http-method>
  10. </web-resource-collection>
  11. <auth-constraint>
  12. <role-name>JBossAdmin</role-name>
  13. </auth-constraint>
  14. </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代码    

Java代码  收藏代码

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

修改该配置为: 

Java代码  收藏代码

  1. <application-policy name = "web-console">
  2. <authentication>
  3. <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
  4. flag = "required">
  5. <module-option name="usersProperties">users.properties</module-option>
  6. <module-option name="rolesProperties">roles.properties</module-option>
  7. </login-module>
  8. </authentication>
  9. </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文件中的<module-option name="usersProperties">users.properties</module-option> 
<module-option name="rolesProperties">roles.properties</module-option> 节点内容时,控制台会抛出异常信息。如下: 

Java代码  收藏代码

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

评论(0)

暂无评论。

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