Search in sources :

Example 21 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDisabledContract.

@Test
public void testDisabledContract() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), new LocalDate().plusMonths(5));
    contract2.setState(ContractState.DISABLED);
    contract2 = identityContractService.save(contract2);
    // 
    IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusMonths(5));
    contract3.setState(ContractState.DISABLED);
    contract3 = identityContractService.save(contract3);
    // 
    IdmIdentityContractDto contract4 = testHelper.createIdentityContact(identity, null, null, null);
    contract4.setState(ContractState.DISABLED);
    contract4 = identityContractService.save(contract4);
    // 
    IdmIdentityContractDto contract5 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), null);
    contract5.setState(ContractState.DISABLED);
    contract5 = identityContractService.save(contract5);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
    // 
    this.recalculateSync(automaticRole.getId());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract2.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract4.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract5.getId());
    assertEquals(0, identityRoles.size());
    // 
    contract5.setState(null);
    contract5 = identityContractService.save(contract5);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract5.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract4.setState(null);
    contract4 = identityContractService.save(contract4);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract4.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract3.setState(null);
    contract3 = identityContractService.save(contract3);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract2.setState(null);
    contract2 = identityContractService.save(contract2);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract2.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
        AbstractIdmAutomaticRoleDto embedded = DtoUtils.getEmbedded(identityRole, IdmAutomaticRoleAttributeService.ROLE_TREE_NODE_ATTRIBUTE_NAME, AbstractIdmAutomaticRoleDto.class, null);
        assertEquals(automaticRole, embedded);
        assertEquals(role.getId(), embedded.getRole());
        assertEquals(role.getId(), identityRole.getRole());
    }
    // 
    contract3.setState(ContractState.DISABLED);
    contract3 = identityContractService.save(contract3);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(org.joda.time.LocalDate) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 22 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleDisableAttribute.

@Test
public void testAutomaticRoleDisableAttribute() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.disabled.getName(), null, "true");
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    identity.setState(IdentityState.DISABLED);
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 23 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleBooleanEav.

@Test
public void testAutomaticRoleBooleanEav() {
    Boolean testValue = true;
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.BOOLEAN);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue.toString());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // change eav value
    testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.BOOLEAN);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 24 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleIntegerEav.

@Test
public void testAutomaticRoleIntegerEav() {
    Integer testValue = 123456;
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.INT);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue.toString());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // change eav value
    testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.INT);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByIdentityAttrWithRecalcualte.

@Test
public void testAssingByIdentityAttrWithRecalcualte() {
    String testValue = "123!@#" + System.currentTimeMillis();
    IdmIdentityDto identity = testHelper.createIdentity();
    identity.setDescription(testValue);
    identity = identityService.save(identity);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, testValue);
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // add new one
    this.recalculateSync(automaticRole.getId());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
    assertNotNull(identityRoleDto.getRoleTreeNode());
    assertEquals(automaticRole.getId(), identityRoleDto.getRoleTreeNode());
    assertEquals(automaticRole.getRole(), identityRoleDto.getRole());
    // 
    // change value and recalculate
    identity.setDescription(testValue + "-test");
    identity = identityService.save(identity);
    // 
    // recalculate isn't needed, is done when save identity contract
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) 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