Discussions

Ask a Question

Could the examples be updated for Play 2.7 please? Http.Context was depreceated and the documentation I found lists older incompatible versions for Deadbolt

This is more of a helper post than a question. I've started a project using Play 2.7(.3) and was following examples (from here and https://github.com/schaloner/deadbolt-2-java/blob/master/QuickStart.md). They show importing slightly older versions of Deadbolt (2.6 and 2.4) Because Http.Context was deprecated in Play 2.7 (https://www.playframework.com/documentation/2.7.x/JavaHttpContextMigration27) you will need to import the newer version. ```"be.objectify" %% "deadbolt-java" % "2.7.0"``` I appreciate the library and all the work!

Jackson deserialiser affected by the Deadbolt "restrict" annotation

see https://stackoverflow.com/questions/56216523/jackson-deserialiser-affected-by-the-deadbolt-restrict-annotation

Example for intigration

Where can i get a simple example for roles with permission for my reference ?
ANSWERED

Exception on start

I have this exception after installing deadbolt dependency on my build.sbt java.lang.NoSuchMethodException: play.core.server.DevServerStart.mainDevHttpMode(play.core.BuildLink, play.core.BuildDocHandler, int, java.lang.String) at java.lang.Class.getMethod(Class.java:1786) at play.runsupport.Reloader$.startDevMode(Reloader.scala:222) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.devModeServer$lzycompute$1(PlayRun.scala:74) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.play$sbt$run$PlayRun$$anonfun$$anonfun$$anonfun$$devModeServer$1(PlayRun.scala:74) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:100) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:53) at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47) I'm using play 2.4 and: "be.objectify" %% "deadbolt-java" % "2.6.4"

error when using @Restrict({@Group("some name")})

I have added the dependencies for deadbolt. when i run localhost:9000 it works fine, but when i use @Restrict({@Group("some name")}) for any api and call that api i get following error [CompletionException: com.google.inject.ConfigurationException: Guice configuration errors: 1) 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:58) while locating be.objectify.deadbolt.java.ConstraintLogic for the 4th parameter of be.objectify.deadbolt.java.actions.RestrictAction.<init>(RestrictAction.java:48) while locating be.objectify.deadbolt.java.actions.RestrictAction 2) 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:58) while locating be.objectify.deadbolt.java.ConstraintLogic for the 4th parameter of be.objectify.deadbolt.java.actions.RestrictAction.<init>(RestrictAction.java:48) while locating be.objectify.deadbolt.java.actions.RestrictAction 2 errors]
ANSWERED

Problem with Template constraints

Hello, Im using play 2.6.5 and deadbolt 2.6.1 java. Im trying to add @subjectPresentOr() {}{} but dont work. im add the import @import be.objectify.deadbolt.java.views.html.di.{subjectPresent, subjectPresentOr} but all time say me Compilation error not found: value subjectPresentOr What are doing wrong? Thanks.

Subject requires we have a List<? extends Role> but Role is an interface, so that's not possible?

Hi I've recently started implementing Deadbolt 2 into my Play Framework app. I've implemented nearly everything, including the handler / cache and etc. It works very well if I manually add a role to a user in the database. However, I cannot edit the roles via code, because I cannot implement any kind of setter as my IDE warns me that the list of roles expects a different kind of object, so I cannot put my custom UserRole object into that list of roles on the Subject. My User object which extends the Subject has the following fields for the Roles and Permissions: @Embedded private List<UserRole> roles; @Embedded private List<UserPermission> permissions; These cannot be List<? extends Role> and List<? extends Permission> because of a MongoDB limitation. It needs to know how to map the embedded objects correctly, so I need to be specific. The getters are things I've overriden from the interface and they are as the interface expects them. Example: @Override public List<? extends Role> getRoles() { return roles; } They seem to work fine, since as I mentioned above, adding a role to the database manually works fine, so clearly the getters must be working properly. They are also causing no warnings. The only problem is I cannot add a UserRole or UserPermission via code. Example: user.getRoles().add(new UserRole("Admin")); OR user.setRoles(rolelist); Both can't be compiled as the IDE complains with the following add(capture<? extends be.objectify.deadbolt.java.models.Role>) in List cannot be applied to (models.security.permissions.UserRole) How do I solve this, please? Kind Regards, Sam

Designing Resource Owner Check

Hi, I would like to create a custom/dynamic constraint where I would check if the resource is owned by the current Subject. Currently, I am solving this by retrieving the requested resource and checking against the created_by field. If it matches, the custom constraint returns true, else false. Now, my problem is that I want to return a 404, instead of 403 (which would be returned by default as the method would return false.), if the resource is not found. How can I design my constraint to do that? Regards, Rishabh
ANSWERED

Error creating bean with name 'interface be.objectify.deadbolt.java.cache.PatternCache':

I'm new to play and upgrading a play 2.0.x app to play 2.5.x, getting following exception, on loading application after "activator run" and loading localhost:9000 from browser play.api.UnexpectedException: Unexpected exception[UnsatisfiedDependencyException: Error creating bean with name 'interface be.objectify.deadbolt.java.cache.PatternCache': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'play.cache.CacheApi' available: expected single matching bean but found 2: interface play.cache.CacheApi,interface play.cache.CacheApi qualified with QualifierInstance(@play.cache.NamedCache(value=play))] at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:180) at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:131) at scala.Option.map(Option.scala:146) at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:131) at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:129) at scala.util.Success.flatMap(Try.scala:231) at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:129) at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:121) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'interface be.objectify.deadbolt.java.cache.PatternCache': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'play.cache.CacheApi' available: expected single matching bean but found 2: interface play.cache.CacheApi,interface play.cache.CacheApi qualified with QualifierInstance(@play.cache.NamedCache(value=play)) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1154) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1056) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'play.cache.CacheApi' available: expected single matching bean but found 2: interface play.cache.CacheApi,interface play.cache.CacheApi qualified with QualifierInstance(@play.cache.NamedCache(value=play)) at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:172) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1114) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1154) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1056) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) I've following findings play.cache.CacheApi has two implementations annotated with @Singleton 1. public class DefaultCacheApi implements CacheApi {} (in "play.cache" package) 2. class EhCacheApi @Inject() (cache: Ehcache) extends CacheApi (in "play.api.cache" package in Chache.scala) how to provide dependency in spring using play 2.5.x, using following deadbolt entry in build.sbt "be.objectify" %% "deadbolt-java" % "2.5.4", note: spring is loaded using https://github.com/remithieblin/play-spring-loader,

Need to inject a DAO-class to my ResourceHandler

In Play 2.4 I used the following code in my isAllowed method: ```java UnitDAO unitDAO = play.Play.application().injector().instanceOf(UnitDAO.class); ``` is it possible to inject a class in a similiar way now when that way is removed by the Play team. Since I can't inject it with the usual way since it's a static context.