Created
May 30, 2012 11:59
-
-
Save bblfish/2835814 to your computer and use it in GitHub Desktop.
Authorization action
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
package org.w3.readwriteweb.play.auth | |
import play.api.mvc._ | |
import javax.security.auth.Subject | |
import java.security.Principal | |
import play.api.libs.concurrent.Promise | |
import java.security.cert.Certificate | |
/** | |
* An Authorization Action | |
* Wraps an Action, which it authorizes (or not) | |
* @param guard a method that filters requests, into those that are authorized (maps to true) and those that are not | |
* @param action the action that will be run if authorized | |
* @tparam A the type of the request body | |
*/ | |
case class AuthZ[A](guard: RequestHeader => Boolean)(action: Action[A]) extends Action[A] { | |
def apply(request: Request[A]): Result = { | |
if (guard(request)) action(request) | |
else Results.Unauthorized | |
} | |
override | |
def parser = action.parser | |
} | |
case class WebAccessControlGuard( | |
subject : RequestHeader => Subject, | |
group: RequestHeader => Group) extends (RequestHeader => Boolean) { | |
def apply(request: RequestHeader) = group(request).member(subject(request)) | |
} | |
trait Group { | |
def member(subj: =>Subject): Boolean | |
} | |
object EveryBody extends Group { | |
def member(subj: =>Subject) = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be used with Play 2.0 Action such as the following, which authorizes all resources starting with "a"