2015-11-11 84 views
1

我正在使用ActiveMQ embedded broker在同一臺機器上編寫測試應用程序。我試過如下進行配置:爲activemq配置授權

activemq.xml

<amq:broker useJmx="false" persistent="false"> 
    <amq:transportConnectors> 
     <amq:transportConnector uri="tcp://localhost:61616" /> 
    </amq:transportConnectors> 
</amq:broker> 

<amq:simpleAuthenticationPlugin > 
    <amq:users> 
     <amq:authenticationUser username="system" password="manager" 
      groups="users,admins" /> 
    </amq:users> 
</amq:simpleAuthenticationPlugin> 

Tomcat的context.xml:!!密碼是不正確故意!

<Resource name="jms/ConnectionFactory" auth="Container" userName="userssname" password="passwords" 
    type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory" 
    factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="tcp://localhost:61616" 
    brokerName="LocalActiveMQBroker" /> 

但是,當我嘗試執行注射,我可以很容易地創建一個ConnectionFactory對象和發送/即使有密碼不正確接收消息。我怎麼能否認這一點?

回答

1

我相信你需要爲隊列和主題添加授權條目。

示例授權插件配置:

<authorizationPlugin> 
    <map> 
     <authorizationMap> 
      <authorizationEntries> 
       <authorizationEntry queue=">" write="admins,publishers" read="admins,consumers" admin="admins" /> 
       <authorizationEntry topic=">" write="admins,publishers" read="admins,consumers" admin="admins" /> 
       <authorizationEntry topic="ActiveMQ.Advisory.>" read="everyone" write="everyone" admin="everyone"/> 
      </authorizationEntries> 
     </authorizationMap> 
    </map> 
</authorizationPlugin> 
+0

太謝謝你了。有用。 –