use of eu.bcvsolutions.idm.core.api.utils.EntityUtils in project CzechIdMng by bcvsolutions.
the class DefaultGrantedAuthoritiesFactory method getGrantedAuthoritiesForValidRoles.
@Override
public Collection<GrantedAuthority> getGrantedAuthoritiesForValidRoles(UUID identityId, Collection<IdmIdentityRoleDto> identityRoles) {
// unique set of authorities from all active identity roles and subroles
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
identityRoles.stream().filter(// valid identity role
EntityUtils::isValid).filter(ir -> {
// valid role's contract
IdmIdentityContractDto contract = DtoUtils.getEmbedded(ir, IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT);
return contract.isValid() && contract.getState() != ContractState.EXCLUDED;
}).forEach(identityRole -> {
IdmRoleDto role = DtoUtils.getEmbedded(identityRole, IdmIdentityRoleDto.PROPERTY_ROLE, (IdmRoleDto) null);
if (role == null) {
role = roleService.get(identityRole.getRole());
}
grantedAuthorities.addAll(getActiveRoleAuthorities(identityId, role, new HashSet<>()));
});
// add default authorities
grantedAuthorities.addAll(authorizationPolicyService.getDefaultAuthorities(identityId));
//
return Lists.newArrayList(trimAdminAuthorities(grantedAuthorities)).stream().sorted(Comparator.comparing(GrantedAuthority::getAuthority)).collect(Collectors.toList());
}
Aggregations