jboss中控制台jmx-console 登录的用户名和密码设置

时间:2022-11-20 17:14:19

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

i)路径:/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml目录下的web.xml文件,查找到<security-constraint/>节点,

<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAdaptor</web-resource-name>
<description>An example security config that onlyallows 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。

i)登录运行角色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>

在此处可以看出,登录的角色、用户等的信息分别在/server/default/conf/props目录下的jmx-console-roles.properties和jmx-console-users.properties文件中设置,分别打开这两个文件。 
其中jmx-console-users.properties文件的内容如下:

# A sample users.properties file foruse with the UsersRolesLoginModule

admin=admin

lanyuan=123

该文件定义的格式为:用户名=密码,在该文件中,默认定义了一个用户名为admin,密码也为admin的用户,读者可将其改成所需的用户名和密码。

同时我添加了一个用户为lanyuan,密码是:123

jmx-console-roles.properties的内容如下:

# A sample roles.properties file foruse with the UsersRolesLoginModule

admin=JBossAdmin,HttpInvoker

lanyuan=JBossAdmin,HttpInvoker

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

同时我为lanyuan添加了角色