Deadbolt for Java

The Deadbolt for Java Developer Hub

Welcome to the Deadbolt for Java developer hub. You'll find comprehensive guides and documentation to help you start working with Deadbolt for Java as quickly as possible, as well as support if you get stuck. Let's jump right in!

This project is supported by Auth0.

If you want to easily add secure authentication and authorization to your Java or Scala projects, feel free to check out Auth0's Java SDK, Scala examples and free plan at auth0.com/overview

Get Started    
Ask A Question

Questions

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

Posted by Samuil Dichev 7 months ago

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

Loading comments...