JBOSS中控制台JMX-CONSOLE 登录的用户名和密码设置

本文指导如何通过编辑JBoss安装目录下的jmx-console.war和web.xml文件,实现JBoss JMX Console的访问需要输入用户名和密码,增加安全性。包括配置安全域、设置角色和用户信息,并通过login-config.xml文件来实现认证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

默认情况访问 http://localhost:8080/jmx-console 就可以浏览jboss的部署管理的一些信息,不需要输入用户名和密码,使用起来有点安全隐患。下面我们针对此问题对jboss进行配置,使得访问jmx- console也必须要知道用户名和密码才可进去访问。步骤如下: 

i) 找到JBoss安装目录/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml文 件,去掉<security-domain>java:/jaas/jmx-console</security- domain>的注释。修改后的该文件内容为: 

<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同级目录下的web.xml文件,查找到<security-constraint/>节点,去掉它的注释,修改后该部分内容为: 

<!-- 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安全域和第二步中的运行角色JBossAdmin都是在login-config.xml中配置,我们在JBoss安 装目录/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文件中设置,分别打开这两个文件。 
其中jmx-console-users.properties文件的内容如下: 

# A sample users.properties file for use with the UsersRolesLoginModule
admin
=admin 

该文件定义的格式为:用户名=密码,在该文件中,默认定义了一个用户名为admin,密码也为admin的用户,读者可将其改成所需的用户名和密码。 
jmx-console-roles.properties的内容如下: 

# A sample roles.properties file for use with the UsersRolesLoginModule
admin
=JBossAdmin, HttpInvoker 

该文件定义的格式为:用户名=角色,多个角色以“,”隔开,该文件默认为admin用户定义了JBossAdmin和HttpInvoker这两个角色。 
配置完成后读者可以通过访问: http://localhost:8088/jmx-console/ ,输入jmx-console-roles.properties文件中定义的用户名和密码,访问jmx-console的页面。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值