scala - Silhouette authorization using request data -
i use silhouette , play 2.4 , i'd restrict actions if securedrequest
body contains wrong.
i know, should use trait authorization
described official docs.
i'm trying following:
case class withcheck(checkcriteria: string) extends authorization[user, cookieauthenticator] { def isauthorized[b](user: user, authenticator: cookieauthenticator)(implicit request: request[b], messages: messages) = { future.successful(user.criteria == checkcriteria) } }
and
def myaction = securedaction(withcheck("bar")) { implicit request => val foo = ...// deserialize object request.body val checkcriteria = foo.criteria // else here }
how can use checkcriteria
value in class withcheck
?
i found solution.
somehow, blind see isauthorized
has same request
implicit parameter. so, check done entirely isauthorized
. example,
case class withcheck() extends authorization[user, cookieauthenticator] { def isauthorized[b](user: user, authenticator: cookieauthenticator)(implicit request: request[b], messages: messages) = { val foo = upickle.read[foo](request.body.tostring()) future.successful(user.criteria == foo.criteria) } }
Comments
Post a Comment