`
whitesock
  • 浏览: 481996 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

ActiveMQ in Action (4)

    博客分类:
  • EE
阅读更多

2.4 Security
    ActiveMQ支持可插拔的安全机制,用以在不同的provider之间切换。
2.4.1 Simple Authentication Plugin
    Simple Authentication Plugin适用于简单的认证需求,或者用于建立测试环境。它允许在XML配置文件中指定用户、用户组和密码等信息。以下是ActiveMQ配置的一个例子:

<plugins>
  ...
  <simpleAuthenticationPlugin>
    <users>
      <authenticationUser username="system" password="manager" groups="users,admins"/>
	  <authenticationUser username="user" password="password" groups="users"/>
      <authenticationUser username="guest" password="password" groups="guests"/>
	</users>
  </simpleAuthenticationPlugin>
</plugins>

 

2.4.2 JAAS Authentication Plugin
    JAAS Authentication Plugin依赖标准的JAAS机制来实现认证。通常情况下,你需要通过设置java.security.auth.login.config系统属性来配置login modules的配置文件。如果没有指定这个系统属性,那么JAAS Authentication Plugin会缺省使用login.config作为文件名。以下是一个login.config文件的例子:

activemq-domain {
    org.apache.activemq.jaas.PropertiesLoginModule required debug=true         org.apache.activemq.jaas.properties.user="users.properties"         org.apache.activemq.jaas.properties.group="groups.properties";
};
    这个login.config文件中设置了两个属性:org.apache.activemq.jaas.properties.user和org.apache.activemq.jaas.properties.group分别用来指向user.properties和group.properties文件。需要注意的是,PropertiesLoginModule使用本地文件的查找方式,而且查找时采用的base directory是login.config文件所在的目录。因此这个login.config说明user.properties和group.properties文件存放在跟login.config文件相同的目录里。
    以下是ActiveMQ配置的一个例子:

<plugins>
  ...
  <jaasAuthenticationPlugin configuration="activemq-domain" />
</plugins>

    基于以上的配置,在JAAS的LoginContext中会使用activemq-domain中配置的PropertiesLoginModule来进行登陆。
    ActiveMQ JAAS还支持LDAPLoginModule、CertificateLoginModule、TextFileCertificateLoginModule等login module。

 

2.4.3 Custom Authentication Implementation
    可以通过编码的方式为ActiveMQ增加认证功能。例如编写一个类继承自XBeanBrokerService。

package com.yourpackage;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.security.SimpleAuthenticationBroker;
import org.apache.activemq.xbean.XBeanBrokerService;

public class SimpleAuthBroker extends XBeanBrokerService {
    //
    private String user;
    private String password;
	
    @SuppressWarnings("unchecked")
    protected Broker addInterceptors(Broker broker) throws Exception {
        broker = super.addInterceptors(broker);
        Map passwords = new HashMap();
        passwords.put(getUser(), getPassword());
        broker = new SimpleAuthenticationBroker(broker, passwords, new HashMap());
        return broker;
    }
	
    public String getUser() {
	    return user;
    }

    public void setUser(String user) {
	    this.user = user;
    }

    public String getPassword() {
	    return password;
    }

    public void setPassword(String password) {
	    this.password = password;
    }
}

    以下是ActiveMQ配置文件的一个例子:

<beans>
  …
  <auth:SimpleAuthBroker
  	xmlns:auth="java://com.yourpackage"
    xmlns="http://activemq.org/config/1.0" brokerName="SimpleAuthBroker1" user="user" password="password" useJmx="true">
  
    <transportConnectors>
      <transportConnector uri="tcp://localhost:61616"/>
    </transportConnectors>
  </auth:SimpleAuthBroker>
  …
</beans>

   在这个配置文件中增加了一个namespace auth,用于指向之前编写的哪个类。同时为SimpleAuthBroker注入了两个属性值user和password,因此在被SimpleAuthBroker改写的addInterceptors方法里,可以使用这两个属性进行认证了。ActiveMQ提供的SimpleAuthenticationBroker类继承自BrokerFilter(可以简单的看成是Broker的Adaptor),它的构造函数中的两个Map分别是userPasswords和userGroups。 SimpleAuthenticationBroker在 addConnection方法中使用userPasswords进行认证,同时会把userGroups的信息保存到ConnectionContext中 。

 

2.4.4 Authorization Plugin
    可以通过Authorization Plugin为认证后的用户授权,以下ActiveMQ配置文件的一个例子:

<plugins>
  <jaasAuthenticationPlugin configuration="activemq-domain"/>
  
  <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> 
17
2
分享到:
评论

相关推荐

    ActiveMQ in Action pdf英文版+源代码

    ActiveMQ in Action pdf英文原版加源代码压缩包。 Apache ActiveMQ in Action is a thorough, practical guide to implementing message-oriented systems in Java using ActiveMQ. The book lays out the core of ...

    ActiveMQ In Action及其源码

    《ActiveMQ In Action》是一本深入探讨Apache ActiveMQ的权威指南,这本书主要涵盖了消息中间件在实际应用中的各种场景和解决方案。ActiveMQ是Apache软件基金会开发的一个开源消息代理,它支持多种消息协议,如...

    ActiveMQ in Action

    根据书籍提供的简介,读者可以预期从《ActiveMQ in Action》中获得从安装和配置到深入开发的全面指导,包括连接到ActiveMQ、消息存储、安全性配置以及构建使用ActiveMQ的应用程序的案例。书籍同样着重介绍了如何利用...

    《ActiveMQ in Action》2010版

    《ActiveMQ in Action》2010版是Manning Publications在2009年发布的一本关于Apache ActiveMQ的专业书籍,旨在深入介绍消息中间件和Java消息服务(JMS)的概念,以及如何有效地使用ActiveMQ。书中包含了第7、9、11、...

    activemq in action PDF 英文版 源代码 合二为一

    《ActiveMQ in Action》是一本深入探讨Apache ActiveMQ的专著,由Michael Burman和Peter Monks撰写。这本书详尽地介绍了如何使用ActiveMQ这一强大的开源消息代理来构建高效、可扩展和可靠的分布式应用程序。英文版是...

    ActiveMQ in action.pdf 英文版

    《ActiveMQ in Action》是一本深受读者欢迎的关于Apache ActiveMQ的权威指南,它深入浅出地介绍了如何在实际环境中运用这一开源消息中间件。ActiveMQ是Java消息服务(JMS)的一个实现,广泛用于分布式系统中的异步...

    ActiveMQ in Action 无水印pdf

    ActiveMQ in Action 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    ActiveMQ in Action最新版

    ActiveMQ 不仅实现了 JMS 规范中定义的所有特性,也额外提供了一些特有且有用的特性。我们会在 3.1 小节详细列说这些特性,并且书中剩余的章节还会继续讨论这些特性。为了演示这些特性,我们创建了两个基于实际业务...

    activemq in action.pdf

    以上概述了《ActiveMQ In Action》这本书的主要知识点,涵盖了从基础知识到实践案例再到高级配置等各个方面。通过学习这些内容,开发者可以深入了解ActiveMQ的工作原理,并能够灵活地将其应用于各种业务场景中。

    ActiveMQ In Action翻译笔记-更新版2011

    ### ActiveMQ In Action翻译笔记-更新版2011 关键知识点详解 #### 一、ActiveMQ概述 **ActiveMQ**是Apache旗下的一款开源、高性能、功能丰富的消息中间件,支持多种消息传递模式,包括点对点(PTP)和发布/订阅...

    activeMq in action 使用activeMq开发JMS的简单讲述

    4. **高可用性**:通过网络集群和故障转移,ActiveMQ可以实现高可用性和负载均衡,确保服务不间断。 5. **高性能**:ActiveMQ采用优化的内存管理和多线程处理,确保了高吞吐量和低延迟。 6. **管理工具**:ActiveMQ...

    ActiveMQ In Action精简版

    根据给定的文件信息,以下是从“ActiveMQ In Action精简版”中提炼出的关键IT知识点,主要聚焦于ActiveMQ的介绍、配置、使用及高级功能。 ### ActiveMQ概述 ActiveMQ是Apache软件基金会下的一个开源项目,它是一款...

    activeMQ in action 2011

    《ActiveMQ in Action 2011》是2011年出版的一本关于Apache ActiveMQ的权威指南,由行业专家撰写,旨在帮助读者深入理解并有效地使用这一强大的消息中间件。ActiveMQ是Apache软件基金会的一个开源项目,它提供了一个...

    ActiveMQ_in_Action_中文.zip

    《ActiveMQ in Action》中文版是一个关于Apache ActiveMQ的详细指南,这是一款广泛使用的开源消息代理,也是Java消息服务(JMS)实现的领先者。这本书深入探讨了ActiveMQ的各个方面,包括其核心功能、使用场景以及...

    ActiveMQ in Action 中文

    ActiveMQ in Action是一本介绍ActiveMQ的书籍,虽然作者未知,但它是对ActiveMQ入门到一般管理非常有帮助的中文资料。该书在英文原版基础上增加了书签功能,方便读者阅读。书中首先介绍了JMS(Java消息服务)规范,...

    ActiveMQ in Action.rar

    《ActiveMQ in Action》这本书是了解和掌握Apache ActiveMQ这一开源消息代理的宝贵资源。ActiveMQ是Apache软件基金会开发的一款企业级的消息中间件,广泛应用于分布式系统中的消息传递和解耦。通过深入阅读这本书,...

    ActiveMQ In Action.zip

    《ActiveMQ In Action》这本书是了解和掌握Apache ActiveMQ这一开源消息中间件的绝佳资源。ActiveMQ是Apache软件基金会开发的一款高效、灵活且可靠的开源消息代理,它支持多种消息协议,如OpenWire、AMQP、STOMP等,...

Global site tag (gtag.js) - Google Analytics