`
zhaohaolin
  • 浏览: 979084 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ActiveMQ实战(4):JMS的安全性【转】

    博客分类:
  • JMS
阅读更多

对于JMS服务的安全控制,ActiveMQ提供两种方式:简单授权方式和JAAS授权方式。我们在这里采用简单的授权方式。如果要实现复杂的权限和角色机制,可以使用JAAS方式,这里不予讲述。

JMS安全的配置,在文件${activemq.base}/conf/activemq-security.xml中有范例。打开该文件,可以看 到,有两个plugins:simpleAuthenticationPlugin和authorizationPlugin,后者是JAAS授权方式需 要用到的,在这里,我们只需要用到前者。

编辑${activemq.base}/conf/activemq.xml文件,加入如下一段代码:

<plugins>

    <simpleAuthenticationPlugin>

        <users>

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

        </users>

    </simpleAuthenticationPlugin>

</plugins>

${activemq.username}和${activemq.password}是在credentials.properties文件中设置的用户名和密码。该文件位于${activemq.base}/conf/目录下,打开该文件,设置你的用户名和密码即可。

配置完毕。这样,你的ActiveMQ就需要用户名和密码才能发送和接收JMS消息了。连接ActiveMQ的Java代码相应的改为如下:

ConnectionFactory cf = new ActiveMQConnectionFactory("myusername", "mypassword", "tcp://192.168.1.109:61616");

在Spring中,则如下:

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">

    <property name="brokerURL" value="tcp://192.168.1.109:61616" />

    <property name="userName" value="myusername" />

    <property name="password" value="password" />

</bean>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics