【问题标题】:Dynamic destination in Apache Apollo MQApache Apollo MQ 中的动态目的地
【发布时间】:2015-06-08 02:47:43
【问题描述】:

有没有办法使用 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 与 Apache ActiveMQ 一起工作,但不确定如何使用 Apollo。

感谢您的帮助。

【问题讨论】:

    标签: jms activemq apollo


    【解决方案1】:

    经过一番摸索后,我想通了。

    在 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)
                    }
                }
            }
        }
    }
    

    以下网址看起来非常有用,实际上几乎完美匹配:

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

    我正在考虑做两个测试:

    1. 速度正是我所需要的
    2. 带有用户名/clientID 替换和 +/*/?/etc 的正则表达式模式匹配器将从配置文件中提取此模式。

    如果它们几乎相同,我可能会通过联系提交者将其添加到 Apollo。

    【讨论】:

      猜你喜欢
      • 2013-01-08
      • 2017-12-27
      • 1970-01-01
      • 2018-01-03
      • 2020-10-03
      • 2016-10-29
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多