I believe that I understood this, mainly because I left some details from the original question, which I did not understand, was important.
The problem was that I was wrapping Action { Action { } }
because the IsAuthenticated
method already had an Action
function call inside it. What I ended up with was an overload of the IsAuthenticated
function using the method that took BodyParser
as a parameter. Since I use the TemporaryFile
method, which is not a subclass of AnyContent
, I also had to change the type of request.
Now here's what my Secured
trait looks like:
def IsAuthenticated(f: => String => Request[Any] => Result) = { Security.Authenticated(username, onUnauthorized) { user => Action(request => f(user)(request)) } } def IsAuthenticated(b: BodyParser[Any] = parse.anyContent) (f: => String => Request[Any] => Result) = { Security.Authenticated(username, onUnauthorized) { user => Action(b)(request => f(user)(request)) } } def HasRole(role: List[String])(b: BodyParser[Any] = parse.anyContent) (f: => String => Request[Any] => Result) = IsAuthenticated(b) { user => request => getRole(user) match { case Some(r) if role.contains(r) => f(user)(request) case _ => Results.Forbidden } }
And here is what my controller looks like:
def controller = HasRole(List("admin"))(parse.temporaryFile) { user => request => request.body match { case b:TemporaryFile => b.moveTo(new File("/tmp/file")) case _ => Status(404) } }
Hope this helps someone else!
source share