Search in sources :

Example 1 with VsSystemImplementerDto

use of eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method updateSystemImplementers.

/**
 * Update identity and role implementers relations
 *
 * @param virtualConfiguration
 * @param systemId
 */
private void updateSystemImplementers(BasicVirtualConfiguration virtualConfiguration, UUID systemId) {
    VsSystemImplementerFilter systemImplementerFilter = new VsSystemImplementerFilter();
    systemImplementerFilter.setSystemId(systemId);
    List<VsSystemImplementerDto> systemImplementers = systemImplementerService.find(systemImplementerFilter, null).getContent();
    // Load implementers from config
    List<IdmIdentityDto> implementersFromConfig = this.loadImplementers(virtualConfiguration.getImplementers());
    // Load roles from config
    List<IdmRoleDto> rolesFromConfig = this.loadImplementerRoles(virtualConfiguration.getImplementerRoles(), implementersFromConfig);
    List<VsSystemImplementerDto> systemImplementersToAdd = new ArrayList<>();
    // Search system-implementers to delete (for identity)
    List<VsSystemImplementerDto> systemImplementersToDelete = systemImplementers.stream().filter(sysImplementer -> {
        return sysImplementer.getIdentity() != null && !implementersFromConfig.contains(new IdmIdentityDto(sysImplementer.getIdentity()));
    }).collect(Collectors.toList());
    // Search implementers to add (for identity)
    List<IdmIdentityDto> implementersToAdd = implementersFromConfig.stream().filter(implementer -> {
        return !systemImplementers.stream().filter(sysImplementer -> {
            return implementer.getId().equals(sysImplementer.getIdentity());
        }).findFirst().isPresent();
    }).collect(Collectors.toList());
    implementersToAdd.forEach(identity -> {
        VsSystemImplementerDto sysImpl = new VsSystemImplementerDto();
        sysImpl.setIdentity(identity.getId());
        sysImpl.setSystem(systemId);
        systemImplementersToAdd.add(sysImpl);
    });
    // Search system-implementers to delete (for role)
    systemImplementersToDelete.addAll(systemImplementers.stream().filter(sysImplementer -> {
        return sysImplementer.getRole() != null && !rolesFromConfig.contains(new IdmRoleDto(sysImplementer.getRole()));
    }).collect(Collectors.toList()));
    // Search implementers to add (for role)
    List<IdmRoleDto> rolesToAdd = rolesFromConfig.stream().filter(implementer -> {
        return !systemImplementers.stream().filter(sysImplementer -> {
            return implementer.getId().equals(sysImplementer.getRole());
        }).findFirst().isPresent();
    }).collect(Collectors.toList());
    rolesToAdd.forEach(role -> {
        VsSystemImplementerDto sysImpl = new VsSystemImplementerDto();
        sysImpl.setRole(role.getId());
        sysImpl.setSystem(systemId);
        systemImplementersToAdd.add(sysImpl);
    });
    // Save changes (add new and remove old)
    systemImplementerService.saveAll(systemImplementersToAdd);
    systemImplementersToDelete.forEach(sysImpl -> {
        systemImplementerService.delete(sysImpl);
    });
}
Also used : Arrays(java.util.Arrays) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) LoggerFactory(org.slf4j.LoggerFactory) VsAccount_(eu.bcvsolutions.idm.vs.entity.VsAccount_) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) Map(java.util.Map) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) IcConnectorConfigurationCzechIdMImpl(eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl) Pageable(org.springframework.data.domain.Pageable) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsOperationType(eu.bcvsolutions.idm.vs.domain.VsOperationType) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) ImmutableMap(com.google.common.collect.ImmutableMap) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) CollectionUtils(org.springframework.util.CollectionUtils) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) VsSystemImplementerService(eu.bcvsolutions.idm.vs.service.api.VsSystemImplementerService) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) VsResultCode(eu.bcvsolutions.idm.vs.exception.VsResultCode) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) Lists(com.google.common.collect.Lists) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) VsSystemImplementerDto(eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcSchemaImpl(eu.bcvsolutions.idm.ic.impl.IcSchemaImpl) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) Logger(org.slf4j.Logger) VsAccountFilter(eu.bcvsolutions.idm.vs.dto.filter.VsAccountFilter) IcSchema(eu.bcvsolutions.idm.ic.api.IcSchema) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTime(org.joda.time.DateTime) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) IcObjectClassInfoImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassInfoImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) VsConfiguration(eu.bcvsolutions.idm.vs.config.domain.VsConfiguration) VsException(eu.bcvsolutions.idm.vs.exception.VsException) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CzechIdMIcConvertUtil(eu.bcvsolutions.idm.ic.czechidm.domain.CzechIdMIcConvertUtil) IcAttributeInfoImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeInfoImpl) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) VsRequestService(eu.bcvsolutions.idm.vs.service.api.VsRequestService) IcException(eu.bcvsolutions.idm.ic.exception.IcException) Assert(org.springframework.util.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) ArrayList(java.util.ArrayList) VsSystemImplementerDto(eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 2 with VsSystemImplementerDto

use of eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto in project CzechIdMng by bcvsolutions.

the class VsRequestByImplementerEvaluator method getPermissions.

@Override
public Set<String> getPermissions(VsRequest authorizable, AuthorizationPolicy policy) {
    Set<String> permissions = super.getPermissions(authorizable, policy);
    if (authorizable == null || authorizable.getSystem() == null || !securityService.isAuthenticated()) {
        return permissions;
    }
    VsSystemImplementerFilter systemImplementerFilter = new VsSystemImplementerFilter();
    systemImplementerFilter.setSystemId(authorizable.getSystem().getId());
    List<VsSystemImplementerDto> implemnters = systemImplementerService.find(systemImplementerFilter, null).getContent();
    UUID currentId = securityService.getCurrentId();
    // Find all valid roles (includes check on contract validity)
    Set<UUID> roles = // 
    identityRoleService.findValidRole(currentId, null).getContent().stream().map(// 
    IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
    for (VsSystemImplementerDto implementer : implemnters) {
        if (implementer.getIdentity() != null && implementer.getIdentity().equals(currentId)) {
            permissions.addAll(policy.getPermissions());
            break;
        }
        if (implementer.getRole() != null && roles.contains(implementer.getRole())) {
            permissions.addAll(policy.getPermissions());
            break;
        }
    }
    return permissions;
}
Also used : VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) VsSystemImplementerDto(eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto) UUID(java.util.UUID)

Example 3 with VsSystemImplementerDto

use of eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto in project CzechIdMng by bcvsolutions.

the class DefaultVsSystemImplementerService method findRequestImplementers.

@Override
public List<IdmIdentityDto> findRequestImplementers(UUID vsSystemId) {
    if (vsSystemId == null) {
        return null;
    }
    VsSystemImplementerFilter filter = new VsSystemImplementerFilter();
    filter.setSystemId(vsSystemId);
    List<VsSystemImplementerDto> requestImplementers = this.find(filter, null).getContent();
    Set<IdmIdentityDto> identities = // 
    requestImplementers.stream().filter(// 
    sysImp -> sysImp.getIdentity() != null).map(// 
    VsSystemImplementerDto::getIdentity).map(// 
    identityService::get).collect(Collectors.toSet());
    // Add identities from all roles
    Set<UUID> roles = // 
    requestImplementers.stream().filter(// 
    sysImp -> sysImp.getRole() != null).map(// 
    VsSystemImplementerDto::getRole).collect(Collectors.toSet());
    roles.forEach(role -> {
        identities.addAll(identityService.findValidByRole(role));
    });
    return new ArrayList<>(identities);
}
Also used : SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) VsSystemImplementerRepository(eu.bcvsolutions.idm.vs.repository.VsSystemImplementerRepository) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) Service(org.springframework.stereotype.Service) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) VsSystemImplementer(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer) VsSystemImplementerDto(eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) VsSystemImplementer_(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer_) List(java.util.List) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) VirtualSystemGroupPermission(eu.bcvsolutions.idm.vs.domain.VirtualSystemGroupPermission) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) VsSystemImplementerService(eu.bcvsolutions.idm.vs.service.api.VsSystemImplementerService) Assert(org.springframework.util.Assert) VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) ArrayList(java.util.ArrayList) VsSystemImplementerDto(eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID)

Aggregations

VsSystemImplementerDto (eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto)3 VsSystemImplementerFilter (eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter)3 UUID (java.util.UUID)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)2 VsSystemImplementerService (eu.bcvsolutions.idm.vs.service.api.VsSystemImplementerService)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Assert (org.springframework.util.Assert)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)1 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)1 SysSystem_ (eu.bcvsolutions.idm.acc.entity.SysSystem_)1 SysSystemEntityService (eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService)1 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1