Skip to content

Instantly share code, notes, and snippets.

@bblfish
Created May 29, 2012 22:19
Show Gist options
  • Save bblfish/2831143 to your computer and use it in GitHub Desktop.
Save bblfish/2831143 to your computer and use it in GitHub Desktop.
Funcional AuthZ
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