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代码
- 1. <jboss-web>
- 2. <security-domain>java:/jaas/jmx-console</security-domain>
- 3. </jboss-web>
<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>
注意:<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代码
<!--此处应与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>
- 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>
- 0. </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代码
- # <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>
<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">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>
- 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> 节点内容时,控制台会抛出异常信息。
出自:http://duqiangcise.javaeye.com/blog/780450
转载于:https://blog.51cto.com/caols0621/427253