Creating an Authorization object.

68 views
Skip to first unread message

Ambrose Laing

unread,
Oct 11, 2016, 11:54:37 AM10/11/16
to Silhouette
My codebase contains the following:

  // Documentation: http://silhouette.mohiva.com/docs/authorization
 
case object Admin extends Authorization[User, CookieAuthenticator] {
   
def isAuthorized[B](user: User, authenticator: CookieAuthenticator)(
     
implicit request: Request[B]) = {
     
Future.successful(user.isAdmin)
   
}
 
}

  val
AdminAction = silhouette.SecuredAction(Admin)
  val
MemberAction = silhouette.SecuredAction

The compilation fails with the following error message:

[error] /home/laing/my/scala-server/app/controllers/Application.scala:553: overloaded method value apply with alternatives:
[error]   (authorization: com.mohiva.play.silhouette.api.Authorization[utils.auth.DefaultEnv#I,utils.auth.DefaultEnv#A])com.mohiva.play.silhouette.api.actions.SecuredActionBuilder[utils.auth.DefaultEnv] <and>
[error]   (errorHandler: com.mohiva.play.silhouette.api.actions.SecuredErrorHandler)com.mohiva.play.silhouette.api.actions.SecuredActionBuilder[utils.auth.DefaultEnv] <and>
[error]   (block: => play.api.mvc.Result)play.api.mvc.Action[play.api.mvc.AnyContent] <and>
[error]   (block: com.mohiva.play.silhouette.api.actions.SecuredRequest[utils.auth.DefaultEnv,play.api.mvc.AnyContent] => play.api.mvc.Result)play.api.mvc.Action[play.api.mvc.AnyContent] <and>
[error]   [A](bodyParser: play.api.mvc.BodyParser[A])(block: com.mohiva.play.silhouette.api.actions.SecuredRequest[utils.auth.DefaultEnv,A] => play.api.mvc.Result)play.api.mvc.Action[A]
[error]  cannot be applied to (Application.this.Admin.type)
[error]   val AdminAction = silhouette.SecuredAction(Admin)
[error]                                ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

When I change the case object to a case class with a dummy argument, I get almost the same error message (it just says the type is Application.this.Admin instead of Application.this.Admin.type).  How do I make the compiler see Admin as an Authorization type?

Thanks

Ambrose

Christian Kaps

unread,
Oct 11, 2016, 4:13:33 PM10/11/16
to Silhouette
For me it works. Is the authenticator defined in DefaultEnv a CookieAuthenticator?
Message has been deleted

Ambrose Laing

unread,
Oct 11, 2016, 6:30:04 PM10/11/16
to Silhouette
Your comment helped me find the mistake -- I had a wrong definition of the User class in DefaultEnv.
Thanks!!!,
Ambrose
Reply all
Reply to author
Forward
0 new messages