User assigned roles list

Hello, how I can get list of assigned roles to user( In code ) and then check if user have specific role providing role name or code?

The entity that stores user assignments is io.jmix.securitydata.entity.RoleAssignmentEntity.

  • username - username of the User
  • roleCode - code of the role (either stored in the database or defined in code).
  • roleType - either or

You can query this entity with DataManager.

1 Like

In case you are interested in roles of the currently authenticated user, use the CurrentAuthentication bean as follows:

private CurrentAuthentication currentAuthentication;

public boolean hasFullAccessRole() {
    return currentAuthentication.getAuthentication().getAuthorities().stream()
            .anyMatch(grantedAuthority ->