I am using Deadbolt2
for authorization. When i, extends
DeadboltHandler
and override their methods, i am getting following error in eclipse:
implements be.objectify.deadbolt.scala.DeadboltHandler.getSubject
overriding method getSubject in trait DeadboltHandler of type [A](request: play.api.mvc.Request[A])Option[be.objectify.deadbolt.core.models.Subject]; method getSubject has incompatible type
These are compile time errors and produce on getSubject
method, because of its return type. I declare its return type as Future[Option[Subject]]
and when i use Option[Subject]
as a return type, the errors is removed. When i saw example by steve
https://github.com/schaloner/deadbolt-2-scala-examples/blob/master/app/security/MyDeadboltHandler.scala, he used Future[Option[Subject]]
and there is no error in code when i import code in eclipse. When i compile the code using activator clean compile
command there is no compile time error.
CODE:
override def getSubject[A](request: Request[A]): Future[Option[Subject]] = {
println("Method Start getSubject");
if(!request.headers.get("userId").isEmpty){
println("If Method Start getSubject");
val userId = request.headers.get("userId").get;
userDao.findById(BSONObjectID.apply(userId));
}else{
println("Else Method Start getSubject");
Future(Option.empty);
}}
Update
When i am using deadbolt be.objectify" %% "deadbolt-scala" % "2.3.2
dependency version, i got compile time error in eclipse and build run successfully. But when i use be.objectify" %% "deadbolt-scala" % "2.3.3
dependency version i am getting build error also.
The signature of getSubject changed in 2.3.3 because the integration with the view layer is flawed. The examples also need updating.
In v2.4 (both Java and Scala versions), all interfaces will return Futures and when blocking calls are needed, e.g. by template restrictions, there will be adapters for the interfaces as required with automatic wrapping.
See the 2.3.3 release notes in the README of https://github.com/schaloner/deadbolt-2-scala - specifically, this bit
DeadboltHandler#getSubject returns an Option[Subject] in place of an Future[Option[Subject]]. Where the subject is needed, the internal code will take care of wrapping the call in a Future.
Sorry for the confusion.