Search in sources :

Example 36 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testFilterHasRules.

@Test
public void testFilterHasRules() {
    long totalElements = automaticRoleAttributeService.find(null).getTotalElements();
    assertEquals(0, totalElements);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(getTestName());
    automaticRole = automaticRoleAttributeService.save(automaticRole);
    // 
    IdmAutomaticRoleFilter filter = new IdmAutomaticRoleFilter();
    filter.setHasRules(true);
    totalElements = automaticRoleAttributeService.find(filter, null).getNumberOfElements();
    assertEquals(0, totalElements);
    // 
    filter.setHasRules(false);
    List<IdmAutomaticRoleAttributeDto> content = automaticRoleAttributeService.find(filter, null).getContent();
    assertEquals(1, content.size());
    IdmAutomaticRoleAttributeDto found = content.get(0);
    assertEquals(automaticRole.getId(), found.getId());
    // 
    automaticRoleAttributeService.deleteInternal(found);
    // 
    automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(getTestName());
    automaticRole = automaticRoleAttributeService.save(automaticRole);
    // 
    IdmAutomaticRoleAttributeRuleDto rule1 = new IdmAutomaticRoleAttributeRuleDto();
    rule1.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule1.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule1.setValue("test");
    rule1.setAttributeName(IdmIdentity_.username.getName());
    rule1.setAutomaticRoleAttribute(automaticRole.getId());
    automaticRoleAttributeRuleService.save(rule1);
    // 
    filter = new IdmAutomaticRoleFilter();
    filter.setHasRules(true);
    content = automaticRoleAttributeService.find(filter, null).getContent();
    assertEquals(1, content.size());
    found = content.get(0);
    assertEquals(automaticRole.getId(), found.getId());
    // 
    // try add next rules
    IdmAutomaticRoleAttributeRuleDto rule2 = new IdmAutomaticRoleAttributeRuleDto();
    rule2.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule2.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule2.setValue("test");
    rule2.setAttributeName(IdmIdentity_.username.getName());
    rule2.setAutomaticRoleAttribute(automaticRole.getId());
    automaticRoleAttributeRuleService.save(rule2);
    // 
    IdmAutomaticRoleAttributeRuleDto rule3 = new IdmAutomaticRoleAttributeRuleDto();
    rule3.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule3.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule3.setValue("test");
    rule3.setAttributeName(IdmIdentity_.username.getName());
    rule3.setAutomaticRoleAttribute(automaticRole.getId());
    automaticRoleAttributeRuleService.save(rule3);
    // 
    filter = new IdmAutomaticRoleFilter();
    filter.setHasRules(true);
    content = automaticRoleAttributeService.find(filter, null).getContent();
    assertEquals(1, content.size());
    found = content.get(0);
    assertEquals(automaticRole.getId(), found.getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 37 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testExpiredContract.

@Test
public void testExpiredContract() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    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());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    IdmIdentityContractDto expiredContract = testHelper.createIdentityContact(identity, null, new LocalDate().minusDays(10), new LocalDate().minusDays(5));
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(expiredContract.getId());
    assertEquals(0, identityRoles.size());
    // 
    expiredContract.setValidTill(new LocalDate().plusDays(100));
    expiredContract = identityContractService.save(expiredContract);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(testHelper.getPrimeContract(identity.getId()).getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    // 
    expiredContract.setValidTill(new LocalDate().minusDays(2));
    expiredContract = identityContractService.save(expiredContract);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    identityRoles = identityRoleService.findAllByContract(expiredContract.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(expiredContract.getId());
    assertEquals(0, identityRoles.size());
    // 
    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) 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 38 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByContractEavAttrWithoutRecalcualte.

@Test
public void testAssingByContractEavAttrWithoutRecalcualte() {
    String testValue = "123!@#" + System.currentTimeMillis();
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    // 
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.SHORTTEXT);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, createEavAttribute.getId(), testValue);
    // 
    primeContract.setPosition(testValue);
    primeContract = identityContractService.save(primeContract);
    // 
    // we need to save eav value, resave identity doesn't enough - we need event eav_save
    testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testValue, PersistentType.SHORTTEXT);
    // 
    List<IdmIdentityRoleDto> 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
    testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testValue + "-test", PersistentType.SHORTTEXT);
    // 
    // recalculate isn't needed, is done when save identity
    // 
    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) 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 39 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testMoreRulesIdentity.

@Test
public void testMoreRulesIdentity() {
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmRoleDto role = testHelper.createRole();
    // 
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    // 
    String email = "test@example.tld";
    String username = getTestName();
    String firstName = "firstName";
    // 
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.email.getName(), null, email);
    // 
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, username);
    // 
    this.recalculateSync(automaticRole.getId());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    identity.setUsername(username);
    identity = identityService.save(identity);
    // 
    // identity hasn't equals email
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    identity.setUsername(username + "test");
    identity.setEmail(email);
    identity = identityService.save(identity);
    // 
    // identity hasn't equals username
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    IdmAutomaticRoleAttributeRuleDto firstNameRule = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.firstName.getName(), null, firstName);
    // 
    identity.setUsername(username);
    identity = identityService.save(identity);
    // 
    // identity hasn't equals firstname (added new rule)
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    identity.setFirstName(firstName);
    identity = identityService.save(identity);
    // 
    // identity has equals all
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identity.setFirstName(firstName + "1");
    identity = identityService.save(identity);
    // 
    // identity hasn't equals firstname
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    automaticRoleAttributeRuleService.delete(firstNameRule);
    // 
    // must recalculate
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    this.recalculateSync(automaticRole.getId());
    // 
    // after recalculate is identity passed all rules
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
}
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) 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 40 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testMoreContracts.

@Test
public void testMoreContracts() {
    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(5), new LocalDate().plusDays(5));
    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());
    identityContractService.delete(contract3);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    identityContractService.delete(contract2);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    identityContractService.delete(primeContract);
    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) 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) LocalDate(org.joda.time.LocalDate) 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