This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request => | |
| request.headers.get("Authorization").flatMap { authorization => | |
| authorization.split(" ").drop(1).headOption.filter { encoded => | |
| new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match { | |
| case u :: p :: Nil if u == username && password == p => true | |
| case _ => false | |
| } | |
| }.map(_ => action(request)) | |
| }.getOrElse { | |
| Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.util._ | |
| import java.security.SecureRandom | |
| import java.security.MessageDigest | |
| /* | |
| * Generates a Bearer Token with a length of | |
| * 32 characters (MD5) or 64 characters (SHA-256) according to the | |
| * specification RFC6750 (http://tools.ietf.org/html/rfc6750) | |
| * | |
| * Uniqueness obtained by hashing system time combined with a |