Created
May 29, 2012 22:19
-
-
Save bblfish/2831143 to your computer and use it in GitHub Desktop.
Funcional AuthZ
This file contains 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
case class AuthZ[A](act: Action[A])(implicit findGuard: RequestHeader => Guard) extends Action[A] { | |
def apply(req: Request): Result = { | |
val guard = findGuard(req) | |
if (guard.allow(guard.subject(req))) act(req) | |
else Results.Unauthorized | |
} | |
override | |
def parser = act.parser | |
} | |
trait Guard { | |
def allow(subj: => Promise[Subject]): Boolean | |
def subject(req: Request): Promise[Subject] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment