Search in sources :

Example 11 with IdmAutomaticRoleAttributeRuleDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testFilterRuleType.

@Test
public void testFilterRuleType() {
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(getTestName());
    automaticRole = automaticRoleAttributeService.save(automaticRole);
    // 
    IdmAutomaticRoleFilter filter = new IdmAutomaticRoleFilter();
    filter.setRuleType(AutomaticRoleAttributeRuleType.CONTRACT);
    List<IdmAutomaticRoleAttributeDto> content = automaticRoleAttributeService.find(filter, null).getContent();
    assertEquals(0, content.size());
    // 
    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.setRuleType(AutomaticRoleAttributeRuleType.CONTRACT);
    content = automaticRoleAttributeService.find(filter, null).getContent();
    assertEquals(0, content.size());
    // 
    // try add next rules
    IdmAutomaticRoleAttributeRuleDto rule2 = new IdmAutomaticRoleAttributeRuleDto();
    rule2.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule2.setType(AutomaticRoleAttributeRuleType.CONTRACT);
    rule2.setValue("test");
    rule2.setAttributeName(IdmIdentityContract_.description.getName());
    rule2.setAutomaticRoleAttribute(automaticRole.getId());
    automaticRoleAttributeRuleService.save(rule2);
    // 
    filter = new IdmAutomaticRoleFilter();
    filter.setRuleType(AutomaticRoleAttributeRuleType.CONTRACT);
    content = automaticRoleAttributeService.find(filter, null).getContent();
    assertEquals(1, content.size());
    IdmAutomaticRoleAttributeDto 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 12 with IdmAutomaticRoleAttributeRuleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto 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 13 with IdmAutomaticRoleAttributeRuleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto 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 14 with IdmAutomaticRoleAttributeRuleDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleRuleCrud.

@Test
public void testAutomaticRoleRuleCrud() {
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto 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());
    IdmAutomaticRoleAttributeRuleDto rule1Saved = automaticRoleAttributeRuleService.save(rule1);
    // 
    assertNotNull(rule1Saved.getId());
    assertEquals(rule1.getComparison(), rule1Saved.getComparison());
    assertEquals(rule1.getValue(), rule1Saved.getValue());
    assertEquals(rule1.getAttributeName(), rule1Saved.getAttributeName());
    assertEquals(rule1.getAutomaticRoleAttribute(), rule1Saved.getAutomaticRoleAttribute());
    // 
    IdmAutomaticRoleAttributeRuleDto rule2 = new IdmAutomaticRoleAttributeRuleDto();
    rule2.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule2.setType(AutomaticRoleAttributeRuleType.CONTRACT);
    rule2.setAttributeName(IdmIdentityContract_.description.getName());
    rule2.setValue("test2");
    rule2.setAutomaticRoleAttribute(automaticRole.getId());
    IdmAutomaticRoleAttributeRuleDto rule2Saved = automaticRoleAttributeRuleService.save(rule2);
    // 
    assertNotNull(rule2Saved.getId());
    assertEquals(rule2.getComparison(), rule2Saved.getComparison());
    assertEquals(rule2.getValue(), rule2Saved.getValue());
    assertEquals(rule2.getAttributeName(), rule2Saved.getAttributeName());
    assertEquals(rule2.getAutomaticRoleAttribute(), rule2Saved.getAutomaticRoleAttribute());
    // 
    // update is allowed
    rule1Saved.setAttributeName(IdmIdentity_.description.getName());
    IdmAutomaticRoleAttributeRuleDto updatedRule1 = automaticRoleAttributeRuleService.save(rule1Saved);
    assertEquals(rule1Saved.getComparison(), updatedRule1.getComparison());
    assertEquals(rule1Saved.getValue(), updatedRule1.getValue());
    assertEquals(rule1Saved.getAttributeName(), updatedRule1.getAttributeName());
    assertEquals(rule1Saved.getAutomaticRoleAttribute(), updatedRule1.getAutomaticRoleAttribute());
    // 
    IdmAutomaticRoleAttributeRuleFilter filter = new IdmAutomaticRoleAttributeRuleFilter();
    filter.setAutomaticRoleAttributeId(automaticRole.getId());
    List<IdmAutomaticRoleAttributeRuleDto> content = automaticRoleAttributeRuleService.find(filter, null).getContent();
    assertEquals(2, content.size());
    // 
    automaticRoleAttributeRuleService.delete(rule1Saved);
    content = automaticRoleAttributeRuleService.find(filter, null).getContent();
    assertEquals(1, content.size());
    IdmAutomaticRoleAttributeRuleDto findAutomaticRole = automaticRoleAttributeRuleService.get(rule1Saved.getId());
    assertNull(findAutomaticRole);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmAutomaticRoleAttributeRuleDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testEmptyIdentityEav.

@Test
public void testEmptyIdentityEav() {
    String testDescription = "testDescription-" + System.currentTimeMillis();
    String eavCode = "eavCode-test-";
    // 
    IdmIdentityDto identity1 = testHelper.createIdentity();
    IdmIdentityDto identity2 = testHelper.createIdentity();
    IdmIdentityDto identity3 = testHelper.createIdentity();
    IdmIdentityContractDto contract1 = testHelper.getPrimeContract(identity1.getId());
    IdmIdentityContractDto contract2 = testHelper.getPrimeContract(identity2.getId());
    IdmIdentityContractDto contract3 = testHelper.getPrimeContract(identity3.getId());
    contract1.setDescription(testDescription);
    contract2.setDescription(testDescription);
    contract3.setDescription(testDescription);
    contract1 = identityContractService.save(contract1);
    contract2 = identityContractService.save(contract2);
    contract3 = identityContractService.save(contract3);
    IdmFormAttributeDto eavAttribute = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.BOOLEAN);
    testHelper.setEavValue(identity1, eavAttribute, IdmIdentity.class, Boolean.TRUE, PersistentType.BOOLEAN);
    IdmRoleDto role1 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role1.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.description.getName(), null, testDescription);
    List<IdmIdentityRoleDto> roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    List<IdmIdentityRoleDto> roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    List<IdmIdentityRoleDto> roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(0, roles1.size());
    assertEquals(0, roles2.size());
    assertEquals(0, roles3.size());
    this.recalculateSync(automaticRole.getId());
    roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, roles1.size());
    assertEquals(1, roles2.size());
    assertEquals(1, roles3.size());
    IdmAutomaticRoleAttributeRuleDto rule = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttribute.getId(), Boolean.TRUE.toString());
    this.recalculateSync(automaticRole.getId());
    roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, roles1.size());
    assertEquals(0, roles2.size());
    assertEquals(0, roles3.size());
    automaticRoleAttributeRuleService.delete(rule);
    this.recalculateSync(automaticRole.getId());
    roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, roles1.size());
    assertEquals(1, roles2.size());
    assertEquals(1, roles3.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) 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)

Aggregations

IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)23 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)15 Test (org.junit.Test)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)9 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)3 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)3 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)3 AutomaticRoleRequestType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType)2