我认为您与身份验证参与者走在正确的轨道上。让身份验证参与者返回 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)
//..
}