Windows下JBoss配置详解

开发 后端
本文向您介绍了在Windows下JBoss配置,并详细描述了JBoss配置时用到的代码。

JBoss配置

1.jmx-console 登录的用户名和密码设置

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

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

 

  1. <jboss-web> 
  2.    <!-- Uncomment the security-domain to enable security. You will  
  3.       need to edit the htmladaptor login configuration to setup the  
  4.       login modules used to authentication users.--> 
  5.       <security-domain>java:/jaas/jmx-console</security-domain> 
  6. </jboss-web> 

2)修改与i)中的jboss-web.xml同级目录下的web.xml文件,查找到<security-constraint/>节点,去掉它的注释,修改后该部分内容为:

 

  1. <!-- A security constraint that restricts access to the HTML JMX console  
  2.    to users with the role JBossAdmin. Edit the roles to what you want and  
  3.    uncomment the WEB-INF/jboss-web.xml/security-domain element to enable  
  4.    secured access to the HTML JMX console.--> 
  5.    <security-constraint> 
  6.      <web-resource-collection> 
  7.        <web-resource-name>HtmlAdaptor</web-resource-name> 
  8.        <description>An example security config that only allows users with the  
  9.          role JBossAdmin to access the HTML JMX console web application  
  10.        </description> 
  11.        <url-pattern>/*</url-pattern> 
  12.        <http-method>GET</http-method> 
  13.        <http-method>POST</http-method> 
  14.      </web-resource-collection> 
  15.      <auth-constraint> 
  16.        <role-name>JBossAdmin</role-name> 
  17.      </auth-constraint> 
  18.    </security-constraint> 

3) 在第一步中的jmx-console安全域和第二步中的运行角色JBossAdmin都是在login-config.xml中配置,我们在JBoss安装目录/server/default/config下找到它,并进行JBoss配置。查找名字为:jmx-console的application-policy:

 

  1. <application-policy name = "jmx-console"> 
  2.        <authentication> 
  3.           <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" 
  4.              flag = "required"> 
  5.            <module-option name="usersProperties">props/jmx-console-users.properties</module-option> 
  6.            <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option> 
  7.           </login-module> 
  8.        </authentication> 
  9.     </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的页面。

2.web-console 登录的用户名和密码设置

默认情况下,用户访问JBoss的web-console时,不需要输入用户名和密码,为了安全起见,我们通过修改配置来为其加上用户名和密码。步骤如下:

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

 

  1. <?xml version='1.0' encoding='UTF-8' ?> 
  2. <!DOCTYPE jboss-web  
  3.     PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"  
  4.     "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd"> 
  5. <jboss-web> 
  6.    <!-- Uncomment the security-domain to enable security. You will  
  7.    need to edit the htmladaptor login configuration to setup the  
  8.    login modules used to authentication users.--> 
  9.    <security-domain>java:/jaas/web-console</security-domain> 
  10.    <!-- The war depends on the --> 
  11.    <depends>jboss.admin:service=PluginManager</depends> 
  12. </jboss-web> 

2)打开1)中jboss-web.xml同目录下的web.xml文件,去掉<security-constraint>部分的注释,修改后的该部分内容为:

 

  1. <!-- A security constraint that restricts access to the HTML JMX console  
  2.    to users with the role JBossAdmin. Edit the roles to what you want and  
  3.    uncomment the WEB-INF/jboss-web.xml/security-domain element to enable  
  4.    secured access to the HTML JMX console.--> 
  5.    <security-constraint> 
  6.    <web-resource-collection> 
  7.    <web-resource-name>HtmlAdaptor</web-resource-name> 
  8.    <description>An example security config that only allows users with the  
  9.    role JBossAdmin to access the HTML JMX console web application  
  10.    </description> 
  11.    <url-pattern>/*</url-pattern> 
  12.    <http-method>GET</http-method> 
  13.    <http-method>POST</http-method> 
  14.    </web-resource-collection> 
  15.    <auth-constraint> 
  16.    <role-name>JBossAdmin</role-name> 
  17.    </auth-constraint> 
  18.    </security-constraint> 

3)打开JBoss安装目录"server"default"conf下的login-config.xml文件,搜索web-console,可找到如下内容:

 

  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> 

以上代码就可以完成JBoss配置了。

【编辑推荐】

  1. 如何解决JBoss和log4j冲突
  2. JBoss集群配置代码实例
  3. JBoss集群配置前言与集群知识
  4. MyEclipse+JBoss配置
  5. JBoss简介告诉我们JBoss是什么
责任编辑:佚名 来源: JavaEye
相关推荐

2010-05-04 10:56:18

jboss负载均衡

2010-05-24 19:42:54

SVN权限配置

2017-01-05 22:28:16

WindowsNano Server部署

2010-05-31 15:55:42

2009-06-03 16:33:53

安装jdk tomcaeclipse配置

2009-06-18 15:15:35

JBoss的配置

2009-06-15 12:59:09

JBoss配置

2009-06-12 14:12:18

JBoss配置MyEclipse

2010-05-24 16:21:55

SVNServer安装

2010-05-24 16:21:55

SVNServer安装

2009-06-15 09:01:19

安装Jboss

2009-06-12 15:54:07

JBoss集群配置

2009-06-15 13:24:46

JBoss数据源

2009-06-15 13:56:02

linux下安装JBo

2009-06-26 17:37:37

JBOSS配置

2009-11-30 09:56:16

2010-05-25 12:41:19

Subversion

2009-07-06 17:49:02

Apache的配置JBoss的配置

2009-06-15 15:10:59

JBoss5时代

2011-03-02 13:23:42

Vsftpd配置
点赞
收藏

51CTO技术栈公众号