Apache Apollo MQ中的动态目的地



是否有方法使用Apache Apollo MQ授权目的地?

我想做的是1) 用户可以只写入共享主题,但将读取限制为服务器/管理员。本主题是向服务器发送消息。2) 用户可以阅读他们自己的私人主题,但除了服务器/管理员之外,没有人可以写。

例如:

Topic               User rights                     Server/Admin rights
/public             Write only                      Read only
/user/foo           ONLY the user foo may read      Write only
/user/bar           ONLY the user bar may read      Write only
/user/<username>    ONLY the <username> may read    Write only

现在来看有趣的部分。这必须适用于动态主题。用户的名字是未知的提前。

我曾使用自定义BrokerFilter与ApacheActiveMQ合作,但不确定如何使用Apollo。

谢谢你的帮助。

经过一番努力,我终于明白了。

在apollo.xml中:

<broker xmlns="http://activemq.apache.org/schema/activemq/apollo" security_factory="com.me.MyAuthorizationPlugin">

在com.me.MyAuthorizationPlugin:

package com.me
import org.fusesource.hawtdispatch.DispatchQueue.QueueType
import org.apache.activemq.apollo.broker.security._
import org.apache.activemq.apollo.broker.{ Queue, Broker, VirtualHost }
import java.lang.Boolean
class MyAuthorizationPlugin extends SecurityFactory {
    def install(broker: Broker) {
        DefaultSecurityFactory.install(broker)
    }
    def install(virtual_host: VirtualHost) {
        DefaultSecurityFactory.install(virtual_host)
        val default_authorizer = virtual_host.authorizer
        virtual_host.authorizer = new Authorizer() {
            def can(ctx: SecurityContext, action: String, resource: SecuredResource): Boolean = {
                println("Resource: " + resource.id + " User: " + ctx.user)
                resource.resource_kind match {
                    case SecuredResource.TopicKind =>
                        val id = resource.id
                        println("Topic Resource: " + id + " User: " + ctx.user)
                        var result : Boolean = id.startsWith("user." + ctx.user) || id.startsWith("MDN." + ctx.user + ".")
                        println("Result: " + result)
                        return result
                    case _ =>
                        return default_authorizer.can(ctx, action, resource)
                }
            }
        }
    }
}

以下URL看起来非常有用,而且几乎完全匹配:

  • https://github.com/apache/activemq-apollo/blob/trunk/apollo-stomp/src/test/resources/apollo-stomp-custom-security.xml#L18

  • https://github.com/apache/activemq-apollo/blob/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/UserOwnershipSecurityFactory.scala#L29

现在我只需要清理我讨厌的scala并将其放入Git中。

我正在考虑做两个测试:

  1. 我所需要的速度
  2. Regex模式匹配器,具有用户名/clientID替换和+/*//etc这个模式将从配置文件中提取

如果它们几乎相同,我可以通过联系commiters将其添加到Apollo中。

最新更新