Search in sources :

Example 26 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDeletePrimariContract.

@Test
public void testDeletePrimariContract() {
    String eavCode = "testingEav";
    UUID testValue1 = UUID.randomUUID();
    Long testValue2 = System.currentTimeMillis();
    Boolean testValue3 = Boolean.FALSE;
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusDays(2));
    IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, new LocalDate().minusDays(2), new LocalDate().plusDays(2));
    IdmIdentityContractDto primeContractCheck = testHelper.getPrimeContract(identity.getId());
    assertEquals(primeContract.getId(), primeContractCheck.getId());
    IdmFormAttributeDto eavAttributeContract1 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
    testHelper.setEavValue(primeContract, eavAttributeContract1, IdmIdentityContract.class, testValue1, PersistentType.UUID);
    IdmFormAttributeDto eavAttributeContract2 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
    testHelper.setEavValue(contract2, eavAttributeContract2, IdmIdentityContract.class, testValue2, PersistentType.LONG);
    IdmFormAttributeDto eavAttributeContract3 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.BOOLEAN);
    testHelper.setEavValue(contract3, eavAttributeContract3, IdmIdentityContract.class, testValue3, PersistentType.BOOLEAN);
    IdmRoleDto role1 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole1 = testHelper.createAutomaticRole(role1.getId());
    testHelper.createAutomaticRoleRule(automaticRole1.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract1.getId(), testValue1.toString());
    IdmRoleDto role2 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole2 = testHelper.createAutomaticRole(role2.getId());
    testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract2.getId(), testValue2.toString());
    IdmRoleDto role3 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole3 = testHelper.createAutomaticRole(role3.getId());
    testHelper.createAutomaticRoleRule(automaticRole3.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract3.getId(), testValue3.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole1.getId());
    this.recalculateSync(automaticRole2.getId());
    this.recalculateSync(automaticRole3.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(3, identityRoles.size());
    boolean contractCheck1 = false;
    boolean contractCheck2 = false;
    boolean contractCheck3 = false;
    // 
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        if (identityRole.getIdentityContract().equals(primeContract.getId())) {
            contractCheck1 = true;
        }
        if (identityRole.getIdentityContract().equals(contract2.getId())) {
            contractCheck2 = true;
        }
        if (identityRole.getIdentityContract().equals(contract3.getId())) {
            contractCheck3 = true;
        }
    }
    assertTrue(contractCheck1);
    assertTrue(contractCheck2);
    assertTrue(contractCheck3);
    identityContractService.delete(primeContract);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    contractCheck1 = false;
    contractCheck2 = false;
    contractCheck3 = false;
    // 
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        if (identityRole.getIdentityContract().equals(primeContract.getId())) {
            contractCheck1 = true;
        }
        if (identityRole.getIdentityContract().equals(contract2.getId())) {
            contractCheck2 = true;
        }
        if (identityRole.getIdentityContract().equals(contract3.getId())) {
            contractCheck3 = true;
        }
    }
    assertFalse(contractCheck1);
    assertTrue(contractCheck2);
    assertTrue(contractCheck3);
    IdmIdentityContractDto newPrimeContract = testHelper.getPrimeContract(identity.getId());
    assertNotEquals(primeContract.getId(), newPrimeContract.getId());
    identityContractService.delete(newPrimeContract);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    contractCheck1 = false;
    contractCheck2 = false;
    contractCheck3 = false;
    // 
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        if (identityRole.getIdentityContract().equals(primeContract.getId())) {
            contractCheck1 = true;
        }
        if (identityRole.getIdentityContract().equals(contract2.getId())) {
            contractCheck2 = true;
        }
        if (identityRole.getIdentityContract().equals(contract3.getId())) {
            contractCheck3 = true;
        }
    }
    assertFalse(contractCheck1);
    assertTrue(contractCheck2);
    assertFalse(contractCheck3);
    IdmIdentityContractDto newNewPrimeContract = testHelper.getPrimeContract(identity.getId());
    assertNotEquals(newPrimeContract.getId(), newNewPrimeContract.getId());
    assertEquals(contract2, newNewPrimeContract);
    identityContractService.delete(newNewPrimeContract);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(org.joda.time.LocalDate) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) UUID(java.util.UUID) 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 27 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithCheck.

@Test
public void testRemoveLastRuleWithCheck() {
    String eavCode = "testingEav";
    Long testEavContractValue = System.currentTimeMillis();
    UUID testEavIdentityValue = UUID.randomUUID();
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmRoleDto role = testHelper.createRole();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    // create two eav attributes (for identity and contract)
    IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.UUID);
    testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.UUID);
    IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
    testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.LONG);
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
    IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule1);
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // in process will be start LRT with async remove all identity roles
    automaticRoleAttributeRuleService.delete(rule2);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 28 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testChangeRule.

@Test
public void testChangeRule() {
    IdmRoleDto role = prepareRole();
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityDto identityTwo = helper.createIdentity();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getName());
    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);
    Assert.assertNotNull(automaticRole.getId());
    IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
    ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
    List<IdmAutomaticRoleAttributeRuleDto> rules = ruleService.find(ruleFilter, null).getContent();
    Assert.assertEquals(1, rules.size());
    rule = rules.get(0);
    rule.setValue(identityTwo.getUsername());
    // Change automatic role via manager
    automaticRole = automaticRoleManager.changeAutomaticRoleRules(automaticRole, true, rule);
    // Find current rules
    rules = ruleService.find(ruleFilter, null).getContent();
    Assert.assertEquals(1, rules.size());
    // We updated rule ... must has same id and changed value
    Assert.assertEquals(rule.getId(), rules.get(0).getId());
    Assert.assertEquals(identityTwo.getUsername(), rules.get(0).getValue());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 29 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testDeleteAutomaticAttributeRoleApproval.

@Test
public void testDeleteAutomaticAttributeRoleApproval() {
    IdmRoleDto role = prepareRole();
    IdmIdentityDto guaranteeIdentity = helper.createIdentity();
    IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
    guarantee.setRole(role.getId());
    guarantee.setGuarantee(guaranteeIdentity.getId());
    role.getGuarantees().add(guarantee);
    role = roleService.save(role);
    IdmIdentityDto identity = helper.createIdentity();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getName());
    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) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) 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 30 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleWithApprovalDisapprove.

@Test
public void testCreateAutomaticAttributeRoleWithApprovalDisapprove() {
    IdmRoleDto role = prepareRole();
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityDto guaranteeIdentity = helper.createIdentity();
    IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
    guarantee.setRole(role.getId());
    guarantee.setGuarantee(guaranteeIdentity.getId());
    role.getGuarantees().add(guarantee);
    role = roleService.save(role);
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getName());
    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
    try {
        automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, false, rule);
    } 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(), "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;
    }
    fail("Automatic role request have to be approving by gurantee!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) 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)

Aggregations

IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)44 Test (org.junit.Test)41 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)30 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)17 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 UUID (java.util.UUID)12 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)7 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 LocalDate (org.joda.time.LocalDate)5 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4