Search in sources :

Example 56 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method init.

/**
 * Cancel all previously ran events
 */
@Override
public void init() {
    LOG.info("Cancel unprocessed events - event was interrupt during instance restart");
    // 
    String instanceId = eventConfiguration.getAsynchronousInstanceId();
    entityEventService.findByState(instanceId, OperationState.RUNNING).forEach(event -> {
        LOG.info("Cancel unprocessed event [{}] - event was interrupt during instance [{}] restart", event.getId(), instanceId);
        // 
        // cancel event
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.EVENT_CANCELED_BY_RESTART, ImmutableMap.of("eventId", event.getId(), "eventType", event.getEventType(), "ownerId", String.valueOf(event.getOwnerId()), "instanceId", event.getInstanceId()));
        OperationResultDto result = new OperationResultDto.Builder(OperationState.CANCELED).setModel(resultModel).build();
        event.setResult(result);
        entityEventService.saveInternal(event);
        // 
        // cancel event states
        IdmEntityStateFilter filter = new IdmEntityStateFilter();
        filter.setEventId(event.getId());
        List<IdmEntityStateDto> states = entityStateManager.findStates(filter, null).getContent();
        states.stream().filter(state -> {
            return OperationState.RUNNING == state.getResult().getState();
        }).forEach(state -> {
            state.setResult(result);
            entityStateManager.saveState(null, state);
        });
    });
    // 
    cacheManager.evictCache(TRANSACTION_EVENT_CACHE_NAME);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) Sort(org.springframework.data.domain.Sort) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) CreatedComparator(eu.bcvsolutions.idm.core.api.domain.comparator.CreatedComparator) EventType(eu.bcvsolutions.idm.core.api.event.EventType) Lazy(org.springframework.context.annotation.Lazy) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Callable(java.util.concurrent.Callable) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) Scheduled(org.springframework.scheduling.annotation.Scheduled) TransactionContext(eu.bcvsolutions.idm.core.api.domain.TransactionContext) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmAuthorityUtils(eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) LongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskExecutor) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) HttpStatus(org.springframework.http.HttpStatus) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) LongRunningTaskEvent(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) Pageable(org.springframework.data.domain.Pageable) Objects(com.google.common.base.Objects) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) ExceptionProcessable(eu.bcvsolutions.idm.core.security.api.service.ExceptionProcessable) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) HashSet(java.util.HashSet) ModelMapper(org.modelmapper.ModelMapper) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) Direction(org.springframework.data.domain.Sort.Direction) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EntityEventLock(eu.bcvsolutions.idm.core.api.event.EntityEventLock) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) Comparator(java.util.Comparator) Collections(java.util.Collections) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Example 57 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmTreeNodeServiceIntegrationTest method testRecountAutomaticRoleWithMissingContent.

@Test
public void testRecountAutomaticRoleWithMissingContent() {
    // create state with missing content
    IdmEntityStateDto state = new IdmEntityStateDto();
    UUID ownerId = UUID.randomUUID();
    state.setOwnerId(ownerId);
    state.setOwnerType(entityStateManager.getOwnerType(IdmRoleTreeNodeDto.class));
    state.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_SKIPPED)).build());
    entityStateManager.saveState(null, state);
    // 
    state = new IdmEntityStateDto();
    state.setOwnerId(ownerId);
    state.setOwnerType(entityStateManager.getOwnerType(IdmRoleTreeNodeDto.class));
    state.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_SKIPPED)).build());
    entityStateManager.saveState(null, state);
    // 
    // recount skipped automatic roles
    LongRunningFutureTask<Boolean> executor = longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
    IdmLongRunningTaskDto longRunningTask = longRunningTaskManager.getLongRunningTask(executor);
    Assert.assertTrue(longRunningTask.getWarningItemCount() > 0);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) ProcessSkippedAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 58 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class DefaultAccAccountManagementService method resolveIdentityAccounts.

@Override
public boolean resolveIdentityAccounts(IdmIdentityDto identity) {
    Assert.notNull(identity, "Identity is required.");
    // find not deleted identity accounts
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    List<AccIdentityAccountDto> allIdentityAccountList = identityAccountService.find(filter, null).getContent();
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    if (CollectionUtils.isEmpty(identityRoles) && CollectionUtils.isEmpty(allIdentityAccountList)) {
        // No roles and accounts ... we don't have anything to do
        return false;
    }
    // account with delete accepted states will be removed on the end
    IdmEntityStateFilter identityAccountStatesFilter = new IdmEntityStateFilter();
    identityAccountStatesFilter.setSuperOwnerId(identity.getId());
    identityAccountStatesFilter.setOwnerType(entityStateManager.getOwnerType(AccIdentityAccountDto.class));
    identityAccountStatesFilter.setResultCode(CoreResultCode.DELETED.getCode());
    List<IdmEntityStateDto> identityAccountStates = entityStateManager.findStates(identityAccountStatesFilter, null).getContent();
    List<AccIdentityAccountDto> identityAccountList = // 
    allIdentityAccountList.stream().filter(ia -> {
        return !// 
        identityAccountStates.stream().anyMatch(state -> {
            return ia.getId().equals(state.getOwnerId());
        });
    }).collect(Collectors.toList());
    // create / remove accounts
    if (!CollectionUtils.isEmpty(identityRoles) || !CollectionUtils.isEmpty(identityAccountList)) {
        List<AccIdentityAccountDto> identityAccountsToCreate = new ArrayList<>();
        List<AccIdentityAccountDto> identityAccountsToDelete = new ArrayList<>();
        // Is role valid in this moment
        resolveIdentityAccountForCreate(identity, identityAccountList, identityRoles, identityAccountsToCreate, identityAccountsToDelete, false, null);
        // Is role invalid in this moment
        resolveIdentityAccountForDelete(identityAccountList, identityRoles, identityAccountsToDelete);
        // Create new identity accounts
        identityAccountsToCreate.forEach(identityAccount -> identityAccountService.save(identityAccount));
        // Delete invalid identity accounts
        identityAccountsToDelete.forEach(identityAccount -> identityAccountService.deleteById(identityAccount.getId()));
    }
    // clear identity accounts marked to be deleted
    // 
    identityAccountStates.stream().forEach(state -> {
        // 
        AccIdentityAccountDto deleteIdentityAccount = identityAccountService.get(state.getOwnerId());
        if (deleteIdentityAccount != null) {
            // identity account can be deleted manually.
            identityAccountService.delete(deleteIdentityAccount);
        }
        entityStateManager.deleteState(state);
    });
    // Return value is deprecated since version 9.5.0  (is useless)
    return true;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AccIdentityAccount_(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount_) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) CollectionUtils(org.springframework.util.CollectionUtils) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) AccAccountManagementService(eu.bcvsolutions.idm.acc.service.api.AccAccountManagementService) HashSet(java.util.HashSet) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Lists(com.google.common.collect.Lists) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemGroupSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemGroupSystemService) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) ArrayList(java.util.ArrayList) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)

Example 59 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class DefaultAccAccountManagementService method deleteIdentityAccount.

@Override
@Transactional
public void deleteIdentityAccount(EntityEvent<IdmIdentityRoleDto> event) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto identityRole = event.getContent();
    Assert.notNull(identityRole, "Identity role is required.");
    Assert.notNull(identityRole, "Identity role identifier is required.");
    // 
    boolean skipPropagate = event.getBooleanProperty(IdmAccountDto.SKIP_PROPAGATE);
    boolean bulk = event.getRootId() != null && entityEventManager.isRunnable(event.getRootId()) && !// check parent event is not role request
    entityEventManager.getEvent(event.getRootId()).getOwnerType().equals(entityEventManager.getOwnerType(IdmRoleRequestDto.class));
    if (!skipPropagate && !bulk) {
        // role is deleted without request or without any parent ... we need to remove account synchronously
        List<UUID> accountIds = deleteIdentityAccount(identityRole);
        // We needs accounts which were connected to deleted identity-role in next
        // processor (we want to execute provisioning only for that accounts)
        event.getProperties().put(ACCOUNT_IDS_FOR_DELETED_IDENTITY_ROLE, (Serializable) accountIds);
        return;
    }
    // Role is deleted in bulk (e.g. role request) - account management has to be called outside
    // we just mark identity account to be deleted and remove identity role
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityRoleId(identityRole.getId());
    // 
    identityAccountService.find(filter, null).getContent().forEach(identityAccount -> {
        // 
        // Set relation on identity-role to null
        identityAccount.setIdentityRole(null);
        if (bulk) {
            // For bulk create entity state for identity account.
            IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
            stateDeleted.setSuperOwnerId(identityAccount.getIdentity());
            stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
            entityStateManager.saveState(identityAccount, stateDeleted);
        } else {
            // Noting identity-accounts for delayed delete and account management
            notingIdentityAccountForDelayedAcm(event, identityAccount, IdmAccountDto.IDENTITY_ACCOUNT_FOR_DELAYED_ACM);
        }
        identityAccountService.save(identityAccount);
    });
    // If default creation of accounts is disabled for this role-system  (or system is in a cross-domain group), then relation between identity
    // and account may not exist. In this scenario we have to made provisioning too.
    // So we try to find these role-systems and its accounts.
    SysRoleSystemFilter roleSystemForProvisioningFilter = new SysRoleSystemFilter();
    roleSystemForProvisioningFilter.setRoleId(identityRole.getRole());
    roleSystemService.find(roleSystemForProvisioningFilter, null).getContent().stream().filter(roleSystem -> {
        if (!roleSystem.isCreateAccountByDefault()) {
            return true;
        } else {
            SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
            systemGroupSystemFilter.setCrossDomainsGroupsForRoleSystemId(roleSystem.getId());
            if (systemGroupSystemService.count(systemGroupSystemFilter) >= 1 && (identityRole.getRoleSystem() == null || roleSystem.getId().equals(identityRole.getRoleSystem()))) {
                // -> Provisioning should be made.
                return true;
            }
        }
        return false;
    }).forEach(roleSystem -> {
        IdmIdentityContractDto contractDto = lookupService.lookupEmbeddedDto(identityRole, IdmIdentityRole_.identityContract);
        AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
        identityAccountFilter.setSystemId(roleSystem.getSystem());
        identityAccountFilter.setIdentityId(contractDto.getIdentity());
        identityAccountService.find(identityAccountFilter, null).getContent().forEach(identityAccount -> {
            // Noting identity-accounts for delayed additional provisioning.
            notingIdentityAccountForDelayedAcm(event, identityAccount, IdmAccountDto.ACCOUNT_FOR_ADDITIONAL_PROVISIONING);
        });
    });
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AccIdentityAccount_(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount_) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) CollectionUtils(org.springframework.util.CollectionUtils) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) AccAccountManagementService(eu.bcvsolutions.idm.acc.service.api.AccAccountManagementService) HashSet(java.util.HashSet) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Lists(com.google.common.collect.Lists) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemGroupSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemGroupSystemService) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class AdGroupConnectorTypeTest method testAssignUserToGroup.

@Test
public void testAssignUserToGroup() {
    ConnectorType connectorType = connectorManager.getConnectorType(MockAdGroupConnectorType.NAME);
    ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
    SysSystemDto systemDto = createSystem(this.getHelper().createName(), connectorTypeDto);
    connectorTypeDto.getMetadata().put(MockAdGroupConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
    connectorTypeDto.setWizardStepName(MockAdGroupConnectorType.STEP_CREATE_USER_TEST);
    // Execute step for testing permissions to create user.
    ConnectorTypeDto stepExecutedResult = connectorManager.execute(connectorTypeDto);
    String entityStateId = stepExecutedResult.getMetadata().get(MockAdGroupConnectorType.ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY);
    assertNotNull(entityStateId);
    IdmEntityStateDto entityStateDto = entityStateService.get(UUID.fromString(entityStateId));
    assertNotNull(entityStateDto);
    connectorTypeDto.setWizardStepName(MockAdGroupConnectorType.STEP_ASSIGN_GROUP_TEST);
    // Execute step for testing permissions to assign user to the group.
    connectorManager.execute(connectorTypeDto);
    entityStateDto = entityStateService.get(UUID.fromString(entityStateId));
    assertNotNull(entityStateDto);
    // Clean
    entityStateService.delete(entityStateDto);
    systemService.delete(systemDto);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) AdGroupConnectorType(eu.bcvsolutions.idm.acc.connector.AdGroupConnectorType) MockAdUserConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdUserConnectorType) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) MockAdGroupConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdGroupConnectorType) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)77 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)43 Test (org.junit.Test)41 UUID (java.util.UUID)40 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)30 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)30 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)24 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)23 List (java.util.List)21 Autowired (org.springframework.beans.factory.annotation.Autowired)21 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)19 Transactional (org.springframework.transaction.annotation.Transactional)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 Lists (com.google.common.collect.Lists)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)15 Assert (org.junit.Assert)14 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13