Search in sources :

Example 1 with EntityUtils

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());
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) HashSet(java.util.HashSet) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) GrantedAuthoritiesFactory(eu.bcvsolutions.idm.core.security.api.service.GrantedAuthoritiesFactory) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) Collection(java.util.Collection) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) GrantedAuthority(org.springframework.security.core.GrantedAuthority) List(java.util.List) Component(org.springframework.stereotype.Component) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Comparator(java.util.Comparator) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) HashSet(java.util.HashSet) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils)

Aggregations

Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 ContractState (eu.bcvsolutions.idm.core.api.domain.ContractState)1 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmAuthorizationPolicyService (eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService)1 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)1 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)1 EntityUtils (eu.bcvsolutions.idm.core.api.utils.EntityUtils)1 DefaultGrantedAuthority (eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority)1 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)1 IdmGroupPermission (eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission)1 IdmAuthenticationException (eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException)1 GrantedAuthoritiesFactory (eu.bcvsolutions.idm.core.security.api.service.GrantedAuthoritiesFactory)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1