Search in sources :

Example 31 with IdmRoleTreeNodeDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testTreeAutomaticRoleDisapprovalWithSecurityWF.

@Test
public void testTreeAutomaticRoleDisapprovalWithSecurityWF() {
    IdmRoleDto role = prepareRole();
    configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + role.getPriority(), APPROVE_ROLE_BY_GUARANTEE_AND_SECURITY_KEY);
    IdmTreeNodeDto nodeOne = getHelper().createTreeNode();
    IdmIdentityDto guaranteeIdentity = getHelper().createIdentity();
    getHelper().createRoleGuarantee(role, guaranteeIdentity);
    IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getCode());
    automaticRole.setTreeNode(nodeOne.getId());
    // Create automatic role via manager
    try {
        automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, false);
    } catch (AcceptedException ex) {
        // The request is in approval
        Assert.assertNotNull(ex.getIdentifier());
        UUID requestId = UUID.fromString(ex.getIdentifier());
        loginAsNoAdmin(guaranteeIdentity.getUsername());
        try {
            // by guarantor
            completeTasksFromUsers(guaranteeIdentity.getUsername(), "disapprove");
        } catch (ResultCodeException e) {
            fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
        } catch (Exception e) {
            fail("Some problem: " + e.getLocalizedMessage());
        }
        IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
        Assert.assertEquals(RequestState.DISAPPROVED, request.getState());
        Assert.assertNull(request.getAutomaticRole());
        return;
    } finally {
        configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + role.getPriority(), APPROVE_ROLE_BY_GUARANTEE_KEY);
    }
    fail("Automatic role request have to be approving by gurantee!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 32 with IdmRoleTreeNodeDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testDeleteAutomaticAttributeRoleApproval.

@Test
public void testDeleteAutomaticAttributeRoleApproval() {
    IdmRoleDto role = prepareRole();
    IdmIdentityDto guaranteeIdentity = getHelper().createIdentity();
    getHelper().createRoleGuarantee(role, guaranteeIdentity);
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getCode());
    IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
    rule.setAttributeName(IdmIdentity_.username.getName());
    rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule.setValue(identity.getUsername());
    // Create automatic role via manager
    automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
    // Delete automatic role via manager
    try {
        automaticRoleManager.deleteAutomaticRole(automaticRole, false);
    } catch (AcceptedException ex) {
        // The request is in approval
        Assert.assertNotNull(ex.getIdentifier());
        UUID requestId = UUID.fromString(ex.getIdentifier());
        loginAsNoAdmin(guaranteeIdentity.getUsername());
        try {
            completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
        } catch (ResultCodeException e) {
            fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
        } catch (Exception e) {
            fail("Some problem: " + e.getLocalizedMessage());
        }
        IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
        Assert.assertEquals(RequestState.EXECUTED, request.getState());
        IdmRoleTreeNodeDto deletedAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
        Assert.assertNull(deletedAutomaticRole);
        return;
    }
    fail("Automatic role request have to be approving by gurantee!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 33 with IdmRoleTreeNodeDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateTreeAutomaticRoleWithRecursion.

@Test
public void testCreateTreeAutomaticRoleWithRecursion() {
    IdmRoleDto role = prepareRole();
    IdmTreeNodeDto nodeOne = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getCode());
    automaticRole.setRecursionType(RecursionType.DOWN);
    automaticRole.setTreeNode(nodeOne.getId());
    // Create automatic role via manager
    automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, true);
    Assert.assertNotNull(automaticRole.getId());
    IdmRoleTreeNodeDto treeAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
    Assert.assertNotNull(treeAutomaticRole);
    Assert.assertEquals(RecursionType.DOWN, treeAutomaticRole.getRecursionType());
    // Create second
    IdmRoleTreeNodeDto automaticRoleTwo = new IdmRoleTreeNodeDto();
    automaticRoleTwo.setRole(role.getId());
    automaticRoleTwo.setName(role.getCode());
    automaticRoleTwo.setRecursionType(RecursionType.UP);
    automaticRoleTwo.setTreeNode(nodeOne.getId());
    // Create automatic role via manager
    IdmRoleTreeNodeDto treeAutomaticRoleTwo = automaticRoleManager.createAutomaticRoleByTree(automaticRoleTwo, true);
    Assert.assertNotNull(treeAutomaticRoleTwo.getId());
    Assert.assertEquals(RecursionType.UP, treeAutomaticRoleTwo.getRecursionType());
    // Create third
    IdmRoleTreeNodeDto automaticRoleThree = new IdmRoleTreeNodeDto();
    automaticRoleThree.setRole(role.getId());
    automaticRoleThree.setName(role.getCode());
    automaticRoleThree.setRecursionType(RecursionType.NO);
    automaticRoleThree.setTreeNode(nodeOne.getId());
    // Create automatic role via manager
    IdmRoleTreeNodeDto treeAutomaticRoleThree = automaticRoleManager.createAutomaticRoleByTree(automaticRoleThree, true);
    Assert.assertNotNull(treeAutomaticRoleThree.getId());
    Assert.assertEquals(RecursionType.NO, treeAutomaticRoleThree.getRecursionType());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 34 with IdmRoleTreeNodeDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method testAssingRoleForContractValidInTheFuture.

@Test
public void testAssingRoleForContractValidInTheFuture() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // 
    IdmIdentityContractDto contractD = new IdmIdentityContractDto();
    contractD.setIdentity(identity.getId());
    contractD.setWorkPosition(nodeD.getId());
    contractD.setValidFrom(LocalDate.now().plusDays(1));
    contractD = service.save(contractD);
    // 
    // create new automatic role
    automaticRoleD = new IdmRoleTreeNodeDto();
    automaticRoleD.setRecursionType(RecursionType.NO);
    automaticRoleD.setRole(roleA.getId());
    automaticRoleD.setTreeNode(nodeD.getId());
    automaticRoleD = saveAutomaticRole(automaticRoleD, true);
    // 
    // check
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contractD.getId());
    assertEquals(1, identityRoles.size());
    assertEquals(automaticRoleD.getId(), identityRoles.get(0).getAutomaticRole());
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 35 with IdmRoleTreeNodeDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method saveAutomaticRole.

/**
 * Save automatic role with repository and manual create and wait for task
 * @param automaticRole
 * @return
 */
private IdmRoleTreeNodeDto saveAutomaticRole(IdmRoleTreeNodeDto automaticRole, boolean withLongRunningTask) {
    // default name
    automaticRole.setName("default");
    IdmRoleTreeNodeDto roleTreeNode = roleTreeNodeService.saveInternal(automaticRole);
    // 
    if (withLongRunningTask) {
        ProcessAutomaticRoleByTreeTaskExecutor task = new ProcessAutomaticRoleByTreeTaskExecutor();
        task.setAutomaticRoles(Lists.newArrayList(roleTreeNode.getId()));
        taskManager.executeSync(task);
    }
    // 
    return roleTreeNodeService.get(roleTreeNode.getId());
}
Also used : ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)83 Test (org.junit.Test)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)48 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)46 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)42 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)39 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)38 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 UUID (java.util.UUID)32 Autowired (org.springframework.beans.factory.annotation.Autowired)20 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)19 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)19 List (java.util.List)19 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)18 ProcessAutomaticRoleByTreeTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)16 Assert (org.junit.Assert)16