1. 程式人生 > >activemq 安全連接

activemq 安全連接

activemq

一、client連接broker

1.1 simple xml configuration

activemq.xml配置

<plugins> 
          <simpleAuthenticationPlugin> 
             <users> 
                 <authenticationUser username="admin" password="password"  groups="admins,publishers,consumers"/>
                 <authenticationUser username="publisher" password="password" groups="publishers,consumers"/> 
                 <authenticationUser username="consumer" password="password" groups="consumers"/> 
                 <authenticationUser username="guest" password="password" groups="guests"/> 
             </users> 
          </simpleAuthenticationPlugin> 
</plugins>

客戶端代碼

activeMQConnectionFactory.createConnection("admin","password");


1.2 JAAS

增加login.config文件

activemq {
    org.apache.activemq.jaas.PropertiesLoginModule required
        org.apache.activemq.jaas.properties.user="users.properties"
        org.apache.activemq.jaas.properties.group="groups.properties"
        reload=true;
};

註:reload設置為true時,用戶名和密碼在每次請求的時候都會重新加載,即修改之後立即生效。


增加users.properties

system=manager
admin=password
user=password
guest=password
sslclient=CN=localhost, OU=activemq.org, O=activemq.org, L=LA, ST=CA, C=US


增加groups.properties

admins=system,sslclient,client,broker1,broker2
tempDestinationAdmins=system,user,sslclient,client,broker1,broker2
users=system,user,sslclient,client,broker1,broker2
guests=guest


activemq.xml配置

        <plugins> 
           <jaasAuthenticationPlugin configuration="activemq" /> 
           <authorizationPlugin> 
               <map> 
                 <authorizationMap> 
                    <authorizationEntries>
                     <authorizationEntry queue="yyc-test" read="guests" write="users" admin="admins" />
                     <authorizationEntry topic="ActiveMQ.Advisory.>" read="all" write="all" admin="all"/>
                   </authorizationEntries>
                   <tempDestinationAuthorizationEntry>
                     <tempDestinationAuthorizationEntry read="tmpDestinationAdmins" write="tmpDestinationAdmins" admin="tmpDestinationAdmins"/>
                   </tempDestinationAuthorizationEntry>
                 </authorizationMap> 
           </map> 
           </authorizationPlugin>
        </plugins>

註:

configuration的值要與login.config中的設置名稱相匹配,如:activemq;

ActiveMQ.Advisory.>以表達式的方式配置的topic一定要設置。因為連接的時候就是這種類型的主題,如果不配置此項話,連接會報錯(沒有權限)。


1.3 LDAP

參考地址:http://activemq.apache.org/security.html


二、broker與broker之間的連接

<networkConnectors>
   <networkConnector name="brokerAbridge"
                     userName="user"
                     password="password"
                     uri="static://(tcp://brokerA:61616)"/>
</networkConnectors>


參考地址:http://activemq.apache.org/security.html

本文出自 “旅行者” 博客,請務必保留此出處http://881206524.blog.51cto.com/10315134/1928683

activemq 安全連接