您的位置:首页 > 其它

activemq之主题、队列设置密码

2017-09-08 16:09 295 查看
除了监视台可以设置用户名和密码外(在conf/jetty.xml中设置),ActiveMQ也可以对各个主题和队列设置用户名和密码(客户端访问broker安全设置)、

1、简单认证插件

SimpleAuthentication Plugin适用于简单的认证需求,或者用于建立测试环境。它允许在XML配置文件中指定用户、用户组和密码等信息。(无法控制到具体的主题队列)

在credentials.properties文件中设置用户名和密码。通过credentials-enc.properties可以对用户名密码进行加密。官方文档地址: http://activemq.apache.org/encrypted-passwords.html 

1)credentials.properties:(activemq的conf下)

[html] view
plain copy

activemq.username=system  

activemq.password=manager  

user.username=zhhgtmq  

user.password=123456  

guest.password=password  

2)在activemq.xml文件systemUsage标签之前加上

[html] view
plain copy

<plugins>  

  <simpleAuthenticationPlugin>  

    <users>  

      <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users,admins"/>  

      <authenticationUser username="${user.username}" password="${user.password}" groups="users"/>  

      <authenticationUser username="guest" password="${guest.password}" groups="guests"/>  

    </users>  

  </simpleAuthenticationPlugin>  

</plugins>   

2、JAAS认证插件

JAAS(Java Authentication and Authorization Service)也就是java的验证Authentication)、授权(Authorization)服务。简单来说,验证Authentication就是要验证一个用户的有效性,即用户名、密码是否正确。

授权Authorization就是授予用户某种角色,可以访问哪些资源。JAASAuthentication Plugin依赖标准的JAAS机制来实现认证。通常情况下,你需要通过设置java.security.auth.login.config系统属性来配置login modules的配置文件。如果没有指定这个系统属性,那么JAAS Authentication Plugin会缺省使用login.config作为文件名。

1)login.config:

在conf下简历login.config文件,内容:

[html] view
plain copy

activemq {  

    org.apache.activemq.jaas.PropertiesLoginModule required  

        org.apache.activemq.jaas.properties.user="users.properties"  

        org.apache.activemq.jaas.properties.group="groups.properties";  

};  

2)users.config

在conf下简历users.config文件,内容:

[html] view
plain copy

system=manager  

user=password  

guest=password  

3)groups.properties:

在conf下简历groups.config文件,内容:

[html] view
plain copy

admins=system,user,guest  

4)在activemq.xml文件systemUsage标签之前加上

[html] view
plain copy

<plugins>  

      <!--  use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->  

      <jaasAuthenticationPlugin configuration="activemq" />  

   

      <!--  lets configure a destination based authorization mechanism -->  

      <authorizationPlugin>  

        <map>  

          <authorizationMap>  

            <authorizationEntries>  

              <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />  

              <authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />  

              <authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />  

                 

              <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />  

              <authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />  

              <authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />  

                 

              <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>  

            </authorizationEntries>  

                        

          </authorizationMap>  

        </map>  

      </authorizationPlugin>  

    </plugins>  

针对不同的queue或者topic设置了可以进行操作的组。里面主要涉及三种操作:read, write, admin

read:可以从queue或者topic里面接收消息
write:可以向queue或者topic发送消息
admin:可以创建queue或者topic(可能还有别的功能)

这些文件配制好时候,ActiveMQ就具有了基本的安全机制,当Client(生产者和消费者)连接ActiveMQ需要使用账号,还可以限制具体的Client对于某个/某些Topic/Queue的操作权限。

例如: 

<authorizationEntry queue=">" read="admins" write="admins" admin="admins" />。 ">"是通配符的意思,也就是admins组的角色,拥有read、write、admin的权限。

<authorizationEntry queue="USERS.>" read="users" write="admins" admin="admins" /> 。queue名称以"USERS."开头的,users组只拥有读权限,即只能收消息,不能发消息。

补充:activemq目录下文件说明

[html] view
plain copy

activemq.xml  

broker.ks  

broker.ts  

broker-localhost.cert  

client.ks  

client.ts  

credentials.properties    //broker连接使用的账号密码文件,明文密码  

credentials-enc.properties ////broker连接使用的账号密码文件,加密的密码  

groups.properties  

jetty.xml  

jetty-realm.properties   //web console访问的账号密码  

jmx.access                                //访问控制文件,用于限制JMX访问权限  

jmx.password       //JMX访问密码文件,用于设置JMX访问的密码  

log4j.properties  

logging.properties  

login.config                   //JAAS认证使用的配置文件,用于指定使用users.properties和groups.properties文件  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: