Guest User

Untitled

a guest
May 4th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request =>
  2. request.headers.get("Authorization").flatMap { authorization =>
  3. authorization.split(" ").drop(1).headOption.filter { encoded =>
  4. new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match {
  5. case u :: p :: Nil if u == username && password == p => true
  6. case _ => false
  7. }
  8. }.map(_ => action(request))
  9. }.getOrElse {
  10. Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""")
  11. }
  12. }
Add Comment
Please, Sign In to add comment