private Set<Role> allAuthorizedRoles(Set<Principal> principals) { Set<Role> roles = new HashSet<>(); /* * It is possible for the admin and observer gids to be the same, * so unfortunately we need to check them separately. */ principals.stream() .filter(GidPrincipal.class::isInstance) .map(GidPrincipal.class::cast) .map(GidPrincipal::getGid) .forEach((gid) -> { if (adminGid != null && gid == adminGid.longValue()) { roles.add(LoginAttributes.adminRole()); } if (observerGid != null && gid == observerGid.longValue()) { roles.add(LoginAttributes.observerRole()); } }); return roles; }