Search in sources :

Example 16 with IdmDelegationDefinitionDto

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

the class DelegationEventListener method onEvent.

@Override
public void onEvent(ActivitiEvent event) {
    LOG.debug("DelegationEventListener - recieve event [{}]", event.getType());
    switch(event.getType()) {
        case TASK_CREATED:
            if (event instanceof ActivitiEntityEventImpl && ((ActivitiEntityEventImpl) event).getEntity() instanceof TaskEntity) {
                TaskEntity taskEntity = (TaskEntity) ((ActivitiEntityEventImpl) event).getEntity();
                if (taskEntity != null && taskEntity.getCandidates() != null) {
                    String processDefinitionId = taskEntity.getProcessDefinitionId();
                    String processDelegationType = delegationManager.getProcessDelegationType(processDefinitionId);
                    if (processDelegationType == null) {
                        // If process doesn't have a delegation type defined, then will be used default.
                        processDelegationType = DefaultDelegationType.NAME;
                    }
                    String delegationType = processDelegationType;
                    taskEntity.getCandidates().forEach(identityLink -> {
                        String user = identityLink.getUserId();
                        Assert.notNull(user, "User id cannot be null!");
                        Assert.isTrue(EntityUtils.isUuid(user), "User id must be UUID in this phase!");
                        UUID userId = UUID.fromString(user);
                        WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
                        mockTask.setId(taskEntity.getId());
                        List<IdmDelegationDefinitionDto> delegationDefinitions = delegationManager.findDelegation(delegationType, userId, null, mockTask);
                        if (CollectionUtils.isEmpty(delegationDefinitions)) {
                            // No delegation found.
                            return;
                        }
                        // Create delegation.
                        delegationDefinitions.forEach(delegationDefinition -> {
                            delegationManager.delegate(mockTask, delegationDefinition);
                            UUID delegate = delegationDefinition.getDelegate();
                            Assert.notNull(delegate, "Delegate cannot be null!");
                            taskEntity.addCandidateUser(delegate.toString());
                        });
                        // Remove delegator form task and add delegate as candidate.
                        taskEntity.deleteUserIdentityLink(user, identityLink.getType());
                        // Add delegator to the task as participant (delegator must have permission for read the task)
                        taskEntity.addUserIdentityLink(user, IdentityLinkType.PARTICIPANT);
                    });
                }
            }
            break;
        case TASK_COMPLETED:
            // Check if exists task delegation for this task and set state on executed.
            if (event instanceof ActivitiEntityEventImpl && ((ActivitiEntityEventImpl) event).getEntity() instanceof TaskEntity) {
                TaskEntity taskEntity = (TaskEntity) ((ActivitiEntityEventImpl) event).getEntity();
                if (taskEntity.getId() != null) {
                    IdmDelegationFilter delegationFilter = new IdmDelegationFilter();
                    delegationFilter.setOwnerId(DtoUtils.toUuid(taskEntity.getId()));
                    delegationFilter.setOwnerType(WorkflowTaskInstanceDto.class.getCanonicalName());
                    IdmDelegationDto delegation = delegationService.find(delegationFilter, null).getContent().stream().findFirst().orElse(null);
                    if (delegation != null) {
                        delegation.setOwnerState(new OperationResultDto(OperationState.EXECUTED));
                        delegationService.save(delegation);
                    }
                }
            }
            break;
        case ACTIVITY_CANCELLED:
            // Check if exists task delegation for this cancelled activity and set state to the cancelled.
            if (event instanceof ActivitiActivityCancelledEvent) {
                // Find activiti task by name (event doesn't contains ID of user task)
                ActivitiActivityCancelledEvent cancelledEvent = (ActivitiActivityCancelledEvent) event;
                TaskQuery taskQuery = taskService.createTaskQuery();
                taskQuery.taskDefinitionKey(cancelledEvent.getActivityId());
                taskQuery.processInstanceId(cancelledEvent.getProcessInstanceId());
                taskQuery.processDefinitionId(cancelledEvent.getProcessDefinitionId());
                // Search a task.
                List<Task> tasks = taskQuery.list();
                if (tasks != null && tasks.size() == 1) {
                    Task task = tasks.get(0);
                    if (task.getId() != null) {
                        WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
                        mockTask.setId(task.getId());
                        List<IdmDelegationDto> delegations = delegationManager.findDelegationForOwner(mockTask);
                        if (!CollectionUtils.isEmpty(delegations)) {
                            delegations.forEach(delegation -> {
                                delegation.setOwnerState(new OperationResultDto(OperationState.CANCELED));
                                delegationService.save(delegation);
                            });
                        }
                    }
                }
            }
            break;
        // Delete IdmDelegations using this workflow task - ensures integrity.
        case ENTITY_DELETED:
            if (event instanceof ActivitiEntityEventImpl && ((ActivitiEntityEventImpl) event).getEntity() instanceof HistoricTaskInstanceEntity) {
                HistoricTaskInstanceEntity taskEntity = (HistoricTaskInstanceEntity) ((ActivitiEntityEventImpl) event).getEntity();
                String taskId = taskEntity.getId();
                Assert.notNull(taskId, "Task ID cannot be null here!");
                IdmDelegationFilter delegationFilter = new IdmDelegationFilter();
                delegationFilter.setOwnerId(DtoUtils.toUuid(taskId));
                delegationFilter.setOwnerType(WorkflowTaskInstanceDto.class.getCanonicalName());
                // Delete delegation connected to this task.
                delegationService.find(delegationFilter, null).getContent().forEach(delegation -> {
                    delegationService.delete(delegation);
                });
            }
            break;
        default:
            LOG.debug("DelegationEventListener - receive not required event [{}]", event.getType());
    }
}
Also used : ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) Task(org.activiti.engine.task.Task) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) HistoricTaskInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity) TaskQuery(org.activiti.engine.task.TaskQuery) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) UUID(java.util.UUID) IdmDelegationFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmDelegationFilter)

Example 17 with IdmDelegationDefinitionDto

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

the class ApproveRoleByManagerDelegationType method findDelegation.

@Override
public List<IdmDelegationDefinitionDto> findDelegation(UUID delegatorId, UUID contractId, BaseDto owner) {
    Assert.isTrue(owner instanceof WorkflowTaskInstanceDto, "Owner must be workflow task for this delegation type!");
    WorkflowTaskInstanceDto task = (WorkflowTaskInstanceDto) owner;
    Object conceptRoleObj = taskInstanceService.getProcessVariable(task.getId(), ROLE_CONCEPT_PROPERTY);
    if (conceptRoleObj instanceof VariableInstance) {
        VariableInstance variableInstance = (VariableInstance) conceptRoleObj;
        conceptRoleObj = variableInstance.getValue();
    }
    if (!(conceptRoleObj instanceof IdmConceptRoleRequestDto)) {
        throw new CoreException(MessageFormat.format("For this delegation type [{0}], must workflow task contains '{1}' [WorkflowTaskInstanceDto] variable", NAME, ROLE_CONCEPT_PROPERTY));
    }
    IdmConceptRoleRequestDto conceptRole = (IdmConceptRoleRequestDto) conceptRoleObj;
    UUID contractFromRequest = conceptRole.getIdentityContract();
    Assert.notNull(contractFromRequest, "Contract ID from the concept of the request cannot be null!");
    // Filtering managers contracts by subordinates contract.
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setIdentity(delegatorId);
    contractFilter.setManagersByContract(contractFromRequest);
    List<IdmIdentityContractDto> managersContracts = identityContractService.find(contractFilter, null).getContent();
    if (managersContracts.isEmpty()) {
        return null;
    }
    Set<IdmDelegationDefinitionDto> resultDelegations = Sets.newHashSet();
    // Find all valid delegation definitions for manager's contract.
    managersContracts.stream().map((managersContract) -> super.findDelegation(delegatorId, managersContract.getId(), owner)).filter((delegations) -> (!CollectionUtils.isEmpty(delegations))).forEachOrdered((delegations) -> {
        resultDelegations.addAll(delegations);
    });
    return Lists.newArrayList(resultDelegations);
}
Also used : IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) UUID(java.util.UUID) Assert(org.modelmapper.internal.util.Assert) Sets(com.google.common.collect.Sets) MessageFormat(java.text.MessageFormat) List(java.util.List) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) AbstractDelegationType(eu.bcvsolutions.idm.core.eav.api.service.AbstractDelegationType) CollectionUtils(org.apache.commons.collections.CollectionUtils) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 18 with IdmDelegationDefinitionDto

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

the class DelegationDefinitionByDelegatorContractEvaluatorTest method testRead.

@Test
public void testRead() {
    IdmIdentityDto delegatorOne = getHelper().createIdentity();
    IdmIdentityDto delegatorTwo = getHelper().createIdentity();
    IdmIdentityContractDto primeContactDelegatorOne = getHelper().getPrimeContract(delegatorOne);
    IdmIdentityContractDto primeContactDelegatorTwo = getHelper().getPrimeContract(delegatorTwo);
    IdmIdentityDto delegateOne = getHelper().createIdentity();
    IdmIdentityDto delegateTwo = getHelper().createIdentity();
    // Create default delegation One.
    IdmDelegationDefinitionDto definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(ApproveRoleByManagerDelegationType.NAME);
    definitionOne.setDelegator(delegatorOne.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setDelegatorContract(primeContactDelegatorOne.getId());
    definitionOne = delegationDefinitionService.save(definitionOne);
    // Create default delegation Two.
    IdmDelegationDefinitionDto definitionTwo = new IdmDelegationDefinitionDto();
    definitionTwo.setType(ApproveRoleByManagerDelegationType.NAME);
    definitionTwo.setDelegator(delegatorTwo.getId());
    definitionTwo.setDelegate(delegateTwo.getId());
    definitionTwo.setDelegatorContract(primeContactDelegatorTwo.getId());
    delegationDefinitionService.save(definitionTwo);
    // 
    List<IdmIdentityDto> identities;
    List<IdmIdentityContractDto> contracts;
    List<IdmDelegationDefinitionDto> delegationDefinitions;
    IdmRoleDto roleWithPermissions = getHelper().createRole();
    // 
    getHelper().createIdentityRole(delegatorOne, roleWithPermissions);
    getHelper().createIdentityRole(delegatorTwo, roleWithPermissions);
    // check - read without policy
    try {
        getHelper().login(delegatorOne.getUsername(), delegatorOne.getPassword());
        // 
        identities = identityService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(identities.isEmpty());
        contracts = contractService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(contracts.isEmpty());
        delegationDefinitions = delegationDefinitionService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(delegationDefinitions.isEmpty());
    } finally {
        logout();
    }
    // 
    // without login
    contracts = contractService.find(null, IdmBasePermission.READ).getContent();
    Assert.assertTrue(contracts.isEmpty());
    // 
    // create authorization policy - assign to role
    // identity
    getHelper().createAuthorizationPolicy(roleWithPermissions.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, SelfIdentityEvaluator.class, IdmBasePermission.READ);
    getHelper().createAuthorizationPolicy(roleWithPermissions.getId(), CoreGroupPermission.IDENTITYCONTRACT, IdmIdentityContract.class, IdentityContractByIdentityEvaluator.class, IdmBasePermission.READ);
    // delegation transitively
    getHelper().createAuthorizationPolicy(roleWithPermissions.getId(), CoreGroupPermission.DELEGATIONDEFINITION, IdmDelegationDefinition.class, DelegationDefinitionByDelegatorContractEvaluator.class);
    // 
    try {
        getHelper().login(delegatorOne.getUsername(), delegatorOne.getPassword());
        // 
        // without update permission
        identities = identityService.find(null, IdmBasePermission.UPDATE).getContent();
        Assert.assertTrue(identities.isEmpty());
        contracts = contractService.find(null, IdmBasePermission.UPDATE).getContent();
        Assert.assertTrue(contracts.isEmpty());
        delegationDefinitions = delegationDefinitionService.find(null, IdmBasePermission.UPDATE).getContent();
        Assert.assertTrue(delegationDefinitions.isEmpty());
        // 
        // evaluate	access
        identities = identityService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, identities.size());
        Assert.assertEquals(delegatorOne.getId(), identities.get(0).getId());
        contracts = contractService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, contracts.size());
        Assert.assertEquals(primeContactDelegatorOne.getId(), contracts.get(0).getId());
        delegationDefinitions = delegationDefinitionService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, delegationDefinitions.size());
        Assert.assertEquals(definitionOne.getId(), delegationDefinitions.get(0).getId());
        // 
        Set<String> permissions = identityService.getPermissions(delegatorOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        permissions = contractService.getPermissions(primeContactDelegatorOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        permissions = delegationDefinitionService.getPermissions(definitionOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
    } finally {
        logout();
    }
}
Also used : DelegationDefinitionByDelegatorContractEvaluator(eu.bcvsolutions.idm.core.security.evaluator.delegation.DelegationDefinitionByDelegatorContractEvaluator) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmDelegationDefinition(eu.bcvsolutions.idm.core.model.entity.IdmDelegationDefinition) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) IdmDelegationDefinitionService(eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ApproveRoleByManagerDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.ApproveRoleByManagerDelegationType) IdentityContractByIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.IdentityContractByIdentityEvaluator) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 19 with IdmDelegationDefinitionDto

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

the class DelegationIntegrationTest method testDelegationDefinitionValiditySameDelegate.

@Test
public void testDelegationDefinitionValiditySameDelegate() {
    IdmIdentityDto delegator = getHelper().createIdentity();
    IdmIdentityDto delegateOne = getHelper().createIdentity();
    // Create default delegations.
    IdmDelegationDefinitionDto definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne = delegationDefinitionService.save(definitionOne);
    IdmDelegationDefinitionDto definitionTwo = new IdmDelegationDefinitionDto();
    definitionTwo.setType(DefaultDelegationType.NAME);
    definitionTwo.setDelegator(delegator.getId());
    definitionTwo.setDelegate(delegateOne.getId());
    definitionTwo = delegationDefinitionService.save(definitionTwo);
    List<IdmDelegationDefinitionDto> delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // Two delegations are valid for this delegator.
    assertEquals(2, delegations.size());
    // Set definition Two as unvalid.
    delegationDefinitionService.delete(definitionTwo);
    definitionTwo = new IdmDelegationDefinitionDto();
    definitionTwo.setDelegator(delegator.getId());
    definitionTwo.setDelegate(delegateOne.getId());
    definitionTwo.setType(DefaultDelegationType.NAME);
    definitionTwo.setValidFrom(LocalDate.now().minusDays(10));
    definitionTwo.setValidTill(LocalDate.now().minusDays(1));
    delegationDefinitionService.save(definitionTwo);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // Only delegation One is valid now.
    assertEquals(1, delegations.size());
    assertEquals(definitionOne.getId(), delegations.get(0).getId());
    // Set definition One as unvalid.
    delegationDefinitionService.delete(definitionOne);
    definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setValidFrom(LocalDate.now().plusDays(20));
    definitionOne.setValidTill(LocalDate.now().plusDays(10));
    definitionOne = delegationDefinitionService.save(definitionOne);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // No delegation is valid now.
    Assert.assertNull(delegations);
    // Set definition One valid in future.
    delegationDefinitionService.delete(definitionOne);
    definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setValidFrom(LocalDate.now().plusDays(20));
    definitionOne.setValidTill(null);
    definitionOne = delegationDefinitionService.save(definitionOne);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // No delegation is valid now.
    Assert.assertNull(delegations);
    // Set definition One as valid.
    delegationDefinitionService.delete(definitionOne);
    definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setValidFrom(LocalDate.now());
    definitionOne.setValidTill(LocalDate.now().plusDays(10));
    definitionOne = delegationDefinitionService.save(definitionOne);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // Only delegation One is valid now.
    assertEquals(1, delegations.size());
    assertEquals(definitionOne.getId(), delegations.get(0).getId());
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 20 with IdmDelegationDefinitionDto

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

the class DelegationIntegrationTest method testDelegationDefinitionValidityDifferentDelegate.

@Test
public void testDelegationDefinitionValidityDifferentDelegate() {
    IdmIdentityDto delegator = getHelper().createIdentity();
    IdmIdentityDto delegateOne = getHelper().createIdentity();
    IdmIdentityDto delegateTwo = getHelper().createIdentity();
    // Create default delegations.
    IdmDelegationDefinitionDto definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne = delegationDefinitionService.save(definitionOne);
    IdmDelegationDefinitionDto definitionTwo = new IdmDelegationDefinitionDto();
    definitionTwo.setType(DefaultDelegationType.NAME);
    definitionTwo.setDelegator(delegator.getId());
    definitionTwo.setDelegate(delegateTwo.getId());
    definitionTwo = delegationDefinitionService.save(definitionTwo);
    List<IdmDelegationDefinitionDto> delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // Two delegations are valid for this delegator.
    assertEquals(2, delegations.size());
    // Set definition Two as unvalid.
    delegationDefinitionService.delete(definitionTwo);
    definitionTwo = new IdmDelegationDefinitionDto();
    definitionTwo.setType(DefaultDelegationType.NAME);
    definitionTwo.setDelegator(delegator.getId());
    definitionTwo.setDelegate(delegateTwo.getId());
    definitionTwo.setValidFrom(LocalDate.now().minusDays(10));
    definitionTwo.setValidTill(LocalDate.now().minusDays(1));
    delegationDefinitionService.save(definitionTwo);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // Only delegation One is valid now.
    assertEquals(1, delegations.size());
    assertEquals(definitionOne.getId(), delegations.get(0).getId());
    // Set definition One as unvalid.
    delegationDefinitionService.delete(definitionOne);
    definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setValidFrom(LocalDate.now().plusDays(20));
    definitionOne.setValidTill(LocalDate.now().plusDays(10));
    definitionOne = delegationDefinitionService.save(definitionOne);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // No delegation is valid now.
    Assert.assertNull(delegations);
    // Set definition One valid in future.
    delegationDefinitionService.delete(definitionOne);
    definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setValidFrom(LocalDate.now().plusDays(20));
    definitionOne.setValidTill(null);
    definitionOne = delegationDefinitionService.save(definitionOne);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // No delegation is valid now.
    Assert.assertNull(delegations);
    // Set definition One as valid.
    delegationDefinitionService.delete(definitionOne);
    definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(DefaultDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne.setValidFrom(LocalDate.now());
    definitionOne.setValidTill(LocalDate.now().plusDays(10));
    definitionOne = delegationDefinitionService.save(definitionOne);
    delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
    // Only delegation One is valid now.
    assertEquals(1, delegations.size());
    assertEquals(definitionOne.getId(), delegations.get(0).getId());
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Aggregations

IdmDelegationDefinitionDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)18 Test (org.junit.Test)14 UUID (java.util.UUID)11 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)10 List (java.util.List)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 IdmDelegationDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 IdmDelegationDefinitionService (eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService)8 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 DefaultDelegationType (eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType)7 ChangeIdentityPermissionTest (eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 Assert (org.junit.Assert)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)6 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)6 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)6