4

如果我想在 Apache ActiveMQ 上实现 JAAS 授权,是否必须使用 activemq.xml 配置文件中的插件?

这种方式确实不好,因为如果我想更改授权,我必须更改 activemq.xml 文件并重新启动服务器才能工作。

有什么方法可以通过更改其他属性文件而不是 activemq.xml 文件来使用 JAAS 身份验证?或者我可以自定义我自己的授权插件吗?

谢谢。

4

2 回答 2

6

每当我设置 ActiveMQ 安全性时,我发现最好使用带有通配符的普通AuthorizationPlugin来表示所覆盖的目的地(这就是为什么在队列和主题中使用命名约定非常方便的原因)。这个想法是您定义少数用户组并授予他们访问这些目的地的权限。

从用户名分配组的角色由身份验证插件之一处理 - JAAS 插件对于将这些信息外部化到 LDAP 目录中的 ActiveMQ 配置之外特别有用。

查看 FuseSource 的ActiveMQ 安全指南(需要注册)以获取更多信息。

更新 2018-07-02 ActiveMQ 安全指南,现在位于 redhat。

于 2012-07-20T09:26:27.920 回答
4

我发现一些代码片段最终对开始研究这个主题非常有帮助:

http://activemq.2283324.n4.nabble.com/Fully-programmatic-authorization-map-tp2344815.html

这是我最终使用它的方式(可能不是最好的方法):

public class TestAuthorizationPlugin extends AuthorizationPlugin {

然后:

@Override
public Broker installPlugin(Broker broker) {
    List<DestinationMapEntry> entries = new ArrayList<DestinationMapEntry>(); 
    try {
        entries.add(makeTopicAuthorization("groupA.topic", "groupA", "groupA", "groupA"));
        entries.add(makeQueueAuthorization("groupA.queue", "groupA", "groupA", "groupA"));
        entries.add(makeQueueAuthorization("groupB.queue", "groupB", "groupB", "groupB"));
        entries.add(makeTopicAuthorization("ActiveMQ.Advisory.>", "all", "all", "all"));
        AuthorizationMap authMap = new DefaultAuthorizationMap(entries);
        return new AuthorizationBroker(broker, authMap);
    } catch (Exception e) {
        LOGGER.error(e);
    } 

    return new AuthorizationBroker(broker, null);
}

把这个罐子塞进去<activemq_home>/lib/

修改activemq.xml:

<plugins>
    <!--  use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->
    <jaasAuthenticationPlugin configuration="activemq" />

    <!-- Authorization control -->
    <bean xmlns="http://www.springframework.org/schema/beans" class="com.blackstrype.activemq.security.TestAuthorizationPlugin"/>
</plugins>

有关 autho plugin dev 更多信息的另一个有用链接:

http://mariuszprzydatek.com/2014/01/04/token-based-authentication-plugin-for-activemq/

于 2015-07-10T15:01:07.320 回答