I'm trying to use deadolt in my java play framework 2.8 projects to only allow some actions in the controller to be called if the request contains an api_key. Reading the guide the best solution is to use Dynamic constraint support. But once the DynamicResourceHandler interface is implemented I always get 4 errors.
In my build.sbt:
libraryDependencies ++= Seq(
guice,
"be.objectify" %% "deadbolt-java" % "2.8.1"
)
In my application.conf
play {
modules {
enabled += be.objectify.deadbolt.java.DeadboltModule
enabled += modules.CustomDeadboltModule
}
}
In my modules a class CustomDeadboltModule
public class CustomDeadboltModule extends AbstractModule {
@Override
public void configure(){
bind(DynamicResourceHandler.class).to(CustomDynamicResourceHandler.class).asEagerSingleton();
}
}
In a package security.deadbolt my class CustomDynamicResourceHandler that implements DynamicResourceHandler interface:
@Singleton
public class CustomDynamicResourceHandler implements DynamicResourceHandler {
@Inject
private com.typesafe.config.Config configuration;
final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public CompletionStage<Boolean> isAllowed(String name, Optional<String> meta, DeadboltHandler deadboltHandler, Http.RequestHeader requestHeader) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
// check if my credential matching current value result= true for instance
return result;
}
@Override
public CompletionStage<Boolean> checkPermission(String permissionValue, Optional<String> meta, DeadboltHandler deadboltHandler, Http.RequestHeader requestHeader) {
return null;
}
}
So in the end I add the @Dynamic to actions in my test controller:
public class HomeController extends Controller {
final Logger logger = LoggerFactory.getLogger(this.getClass());
@Dynamic("")
public Result index() {
return ok("ok");
}
}
So when I try to perform a request I receive this error:
> 1) No implementation for
> be.objectify.deadbolt.java.cache.BeforeAuthCheckCache was bound.
> while locating be.objectify.deadbolt.java.cache.BeforeAuthCheckCache
> for the 2nd parameter of be.objectify.deadbolt.java.actions.DynamicAction.<init>(DynamicAction.java:46)
> while locating be.objectify.deadbolt.java.actions.DynamicAction
>
> 2) No implementation for be.objectify.deadbolt.java.cache.HandlerCache
> was bound. while locating
> be.objectify.deadbolt.java.cache.HandlerCache
> for the 1st parameter of be.objectify.deadbolt.java.actions.DynamicAction.<init>(DynamicAction.java:46)
> while locating be.objectify.deadbolt.java.actions.DynamicAction
>
> 3) No implementation for be.objectify.deadbolt.java.cache.PatternCache
> was bound. while locating
> be.objectify.deadbolt.java.cache.PatternCache
> for the 3rd parameter of be.objectify.deadbolt.java.ConstraintLogic.<init>(ConstraintLogic.java:53)
> while locating be.objectify.deadbolt.java.ConstraintLogic
> for the 4th parameter of be.objectify.deadbolt.java.actions.DynamicAction.<init>(DynamicAction.java:46)
> while locating be.objectify.deadbolt.java.actions.DynamicAction
>
> 4) No implementation for be.objectify.deadbolt.java.cache.SubjectCache
> was bound. while locating
> be.objectify.deadbolt.java.cache.SubjectCache
> for the 2nd parameter of be.objectify.deadbolt.java.ConstraintLogic.<init>(ConstraintLogic.java:53)
> while locating be.objectify.deadbolt.java.ConstraintLogic
> for the 4th parameter of be.objectify.deadbolt.java.actions.DynamicAction.<init>(DynamicAction.java:46)
> while locating be.objectify.deadbolt.java.actions.DynamicAction