How to hide Akka remote actors from lookup?

╄→гoц情女王★ 提交于 2019-12-03 16:32:02

I think you were on the right track with the authentication actor. Have the authentication actor return both the ActorRef and a token. The remote actors must include that token in messages to your local worker actor. The worker actor will validate the token before doing the work.

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)
    //..
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!