activemq之主题、队列设置密码

除了监视台可以设置用户名和密码外(在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
  1. activemq.username=system  
  2. activemq.password=manager  
  3. user.username=zhhgtmq  
  4. user.password=123456  
  5. guest.password=password  
2)在activemq.xml文件systemUsage标签之前加上

[html]  view plain  copy
  1. <plugins>  
  2.   <simpleAuthenticationPlugin>  
  3.     <users>  
  4.       <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users,admins"/>  
  5.       <authenticationUser username="${user.username}" password="${user.password}" groups="users"/>  
  6.       <authenticationUser username="guest" password="${guest.password}" groups="guests"/>  
  7.     </users>  
  8.   </simpleAuthenticationPlugin>  
  9. </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
  1. activemq {  
  2.     org.apache.activemq.jaas.PropertiesLoginModule required  
  3.         org.apache.activemq.jaas.properties.user="users.properties"  
  4.         org.apache.activemq.jaas.properties.group="groups.properties";  
  5. };  
2)users.config

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

[html]  view plain  copy
  1. system=manager  
  2. user=password  
  3. guest=password  

3)groups.properties:

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

[html]  view plain  copy
  1. admins=system,user,guest  

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

[html]  view plain  copy
  1. <plugins>  
  2.       <!--  use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->  
  3.       <jaasAuthenticationPlugin configuration="activemq" />  
  4.    
  5.       <!--  lets configure a destination based authorization mechanism -->  
  6.       <authorizationPlugin>  
  7.         <map>  
  8.           <authorizationMap>  
  9.             <authorizationEntries>  
  10.               <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />  
  11.               <authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />  
  12.               <authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />  
  13.                  
  14.               <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />  
  15.               <authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />  
  16.               <authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />  
  17.                  
  18.               <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>  
  19.             </authorizationEntries>  
  20.                         
  21.           </authorizationMap>  
  22.         </map>  
  23.       </authorizationPlugin>  
  24.     </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
  1. activemq.xml  
  2. broker.ks  
  3. broker.ts  
  4. broker-localhost.cert  
  5. client.ks  
  6. client.ts  
  7. credentials.properties    //broker连接使用的账号密码文件,明文密码  
  8. credentials-enc.properties broker连接使用的账号密码文件,加密的密码  
  9. groups.properties  
  10. jetty.xml  
  11. jetty-realm.properties   //web console访问的账号密码  
  12. jmx.access                                //访问控制文件,用于限制JMX访问权限  
  13. jmx.password       //JMX访问密码文件,用于设置JMX访问的密码  
  14. log4j.properties  
  15. logging.properties  
  16. login.config                   //JAAS认证使用的配置文件,用于指定使用users.properties和groups.properties文件  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值