加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 如何从查找中隐藏Akka远程actor?

发布时间:2020-12-16 08:48:07 所属栏目:安全 来源:网络整理
导读:我正在运行Akka 2.0.2微内核,并希望为不受信任的远程actor执行身份验证方案. 首先要想到的是设置一个身份验证actor,它在身份验证成功时返回对工作actor的引用. 但是,我应该如何保护工作者不仅仅是通过actorFor()直接远程查找,完全绕过身份验证? 也就是说,我
我正在运行Akka 2.0.2微内核,并希望为不受信任的远程actor执行身份验证方案.

首先要想到的是设置一个身份验证actor,它在身份验证成功时返回对工作actor的引用.

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

也就是说,我想阻止远程actor在没有身份验证的情况下访问我的微内核actor系统中的actor.

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

解决方法

我认为你与认证演员走在了正确的轨道上.让身份验证actor返回ActorRef和令牌.远程actor必须在消息中包含该令牌给您当地的worker actor.工作者将在完成工作之前验证令牌.

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)
    //..
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读