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!

Get Started    
Ask A Question


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

Submitted by Samuil Dichev 21 days ago


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:

private List<UserRole> roles;

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:

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"));



Both can't be compiled as the IDE complains with the following
add(capture<? extends>) in List cannot be applied to (

How do I solve this, please?

Kind Regards,


Loading comments...