В итоге я обнаружил, что создание собственного AuthProvider (или, скорее, переопределение существующего BasicAuthProvider) и добавление MarkerContext
является самым простым. Как это:
class BasicAuthProvider @Inject()(
override protected val authInfoRepository: AuthInfoRepository,
override protected val passwordHasherRegistry: PasswordHasherRegistry)(implicit override val executionContext: ExecutionContext)
extends providers.BasicAuthProvider(authInfoRepository, passwordHasherRegistry)(executionContext) {
/**
* Authenticates an identity based on credentials sent in a request.
*
* @param request The request.
* @tparam B The type of the body.
* @return Some login info on successful authentication or None if the authentication was unsuccessful.
*/
override def authenticate[B](request: Request[B]): Future[Option[LoginInfo]] = {
getCredentials(request) match {
case Some(credentials) =>
val loginInfo = LoginInfo(id, credentials.identifier)
val marker: org.slf4j.Marker =
MarkerFactory.getMarker(loginInfo.toString)
implicit val mc: MarkerContext = MarkerContext(marker)
authenticate(loginInfo, credentials.password).map {
case Authenticated => Some(loginInfo)
case InvalidPassword(error) =>
logger.warn(error)
None
case UnsupportedHasher(error) => throw new ConfigurationException(error)
case NotFound(error) =>
logger.warn(error)
None
}
case None => Future.successful(None)
}
}
}