【问题标题】:How to hide Akka remote actors from lookup?如何从查找中隐藏 Akka 远程演员?
【发布时间】:2012-08-08 22:35:53
【问题描述】:

我正在运行 Akka 2.0.2 微内核并希望为不受信任的远程参与者实施身份验证方案。

首先想到的是设置一个身份验证参与者,它在身份验证成功时返回对工作参与者的引用。

但是,我应该如何保护工作参与者不被直接通过 actorFor() 远程查找,从而完全绕过身份验证?

也就是说,我想防止远程参与者未经身份验证访问我的微内核参与者系统中的参与者。

在 actorOf() 中不给工作 actor 一个名字是不够的,因为它会得到一个容易猜到的自动生成的名字。有没有办法禁用演员的远程查找,但仍然能够将他们的 ActorRef 提供给远程系统?

【问题讨论】:

  • 我不知道。你最好在 Akka 邮件列表上询问,因为这可能是一个功能请求。
  • 你想阻止远程actor在没有身份验证的情况下访问你的ActorSystem中的actor,还是你想阻止你的ActorSystem中的actor在没有身份验证的情况下访问远程actor?
  • 我想阻止远程参与者在未经身份验证的情况下访问我的微内核参与者系统中的参与者。我编辑了这个问题,试图澄清这一点。

标签: scala authentication remoting actor akka


【解决方案1】:

我认为您与身份验证参与者的合作是正确的。让身份验证参与者返回 ActorRef 和令牌。远程参与者必须在发送给本地工作者参与者的消息中包含该令牌。工人演员将在工作之前验证令牌。

trait AuthenticatingActor { this => Actor
  val authenticationService = //...

  def receive = {
    case UnauthenticatedRequest(token, msg) =>
      if (authenticationService.validate(token) 
        authenticatedRecieve(msg)
      else
        sender ! RequestNotAuthenticated(token, "token invalid")

  def authenticatedReceive: Receive
}

class Worker extends AuthenticatingActor with Actor {
  def authenticatedReceive: Receive = //..
}

class AuthenticationActor extends Actor {
  val authenticationService = //..
  var worker: ActorRef = _

  def receive = {
    case Authenticate(username, password) =>
      val token = authenticationService.authenticate(username, password)
      sender ! token.map(AuthenticationSuccess(_, worker).
                     getOrElse(AuthenticationFailure)
    //..
}

【讨论】:

  • 谢谢! - 你的回答给了我另一个想法:如何简单地通过 actorOf() 给工作演员一个长的、安全随机的(类似令牌的)名称,并且真的只是将 ActorRef 返回给它而不是使用额外的令牌? - 或者这是一个愚蠢的想法?
  • 嗯 - 我认为你的工人仍然可以使用 actorSystem.actorSelection
  • 你说得对,我没有想到这一点。那么它就是显式标记。
猜你喜欢
  • 2014-05-28
  • 1970-01-01
  • 2012-05-09
  • 1970-01-01
  • 2015-09-08
  • 2014-03-16
  • 1970-01-01
  • 2012-02-25
  • 2016-01-24
相关资源
最近更新 更多