use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method addSuperAdminRoleWithSubprocessRemoveTest.
@Test
@Transactional
public void addSuperAdminRoleWithSubprocessRemoveTest() {
IdmIdentityDto test1 = helper.createIdentity("TestUser" + System.currentTimeMillis());
IdmIdentityDto test2 = identityService.getByUsername(InitTestData.TEST_USER_2);
loginAsAdmin(InitTestData.TEST_USER_2);
IdmIdentityContractDto contract = identityContractService.getPrimeContract(test1.getId());
IdmRoleDto adminRole = helper.createRole("testRole" + System.currentTimeMillis());
adminRole.setApproveRemove(true);
roleService.save(adminRole);
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
concept = conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
// HELPDESK
taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
// MANAGER
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
// USER MANAGER
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
// SECURITY
taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.EXECUTED, request.getState());
assertNotNull(request.getWfProcessId());
concept = conceptRoleRequestService.get(concept.getId());
assertNotNull(concept.getWfProcessId());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(test1.getId());
Page<IdmIdentityRoleDto> page = identityRoleService.find(filter, null);
assertEquals(1, page.getContent().size());
loginAsAdmin(InitTestData.TEST_USER_2);
// Guarantee
int priority = 500;
adminRole.setPriority(priority);
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(adminRole.getId());
guarantee.setGuarantee(test2.getId());
adminRole.getGuarantees().add(guarantee);
adminRole = roleService.save(adminRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + (priority + priority), APPROVE_REMOVE_ROLE_BY_MANAGER_KEY);
IdmRoleRequestDto requestRemove = createRoleRequest(test1);
requestRemove = roleRequestService.save(requestRemove);
IdmConceptRoleRequestDto conceptRemove = createRoleRemoveConcept(page.getContent().get(0).getId(), adminRole, contract, requestRemove);
conceptRemove = conceptRoleRequestService.save(conceptRemove);
roleRequestService.startRequestInternal(requestRemove.getId(), true);
requestRemove = roleRequestService.get(requestRemove.getId());
assertEquals(RoleRequestState.IN_PROGRESS, requestRemove.getState());
WorkflowFilterDto taskRemoveFilter = new WorkflowFilterDto();
// HELPDESK
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// MANAGER
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// USER MANAGER
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// Subprocess - approve by GUARANTEE
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// SECURITY
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
requestRemove = roleRequestService.get(requestRemove.getId());
assertEquals(RoleRequestState.EXECUTED, requestRemove.getState());
assertNotNull(requestRemove.getWfProcessId());
conceptRemove = conceptRoleRequestService.get(conceptRemove.getId());
assertNotNull(conceptRemove.getWfProcessId());
IdmIdentityRoleFilter filterRemove = new IdmIdentityRoleFilter();
filterRemove.setIdentityId(test1.getId());
Page<IdmIdentityRoleDto> pageRemove = identityRoleService.find(filterRemove, null);
assertEquals(0, pageRemove.getContent().size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityRoleServiceTest method roleCatalogueTest.
@Test
public void roleCatalogueTest() {
IdmIdentityDto person = testHelper.createIdentity();
IdmIdentityDto person2 = testHelper.createIdentity();
IdmRoleCatalogueDto catalogue = testHelper.createRoleCatalogue();
IdmRoleCatalogueRoleDto catalogueRole = new IdmRoleCatalogueRoleDto();
IdmRoleCatalogueRoleDto catalogueRole2 = new IdmRoleCatalogueRoleDto();
IdmIdentityContractDto contract = testHelper.createIdentityContact(person);
IdmIdentityContractDto contract2 = testHelper.createIdentityContact(person2);
IdmRoleDto role = testHelper.createRole();
IdmRoleDto role2 = testHelper.createRole();
catalogueRole.setRoleCatalogue(catalogue.getId());
catalogueRole.setRole(role.getId());
catalogueRole2.setRoleCatalogue(catalogue.getId());
catalogueRole2.setRole(role2.getId());
IdmIdentityRoleDto roleCover = testHelper.createIdentityRole(contract, role);
IdmIdentityRoleDto roleCover2 = testHelper.createIdentityRole(contract2, role2);
idmRoleCatalogueRoleService.save(catalogueRole);
idmRoleCatalogueRoleService.save(catalogueRole2);
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleCatalogueId(catalogue.getId());
Page<IdmIdentityRoleDto> result = idmIdentityRoleService.find(filter, null);
assertEquals("Wrong CatalogueRoleId", roleCover.getId(), result.getContent().get(0).getId());
assertEquals("Wrong CatalogueRoleId2", roleCover2.getId(), result.getContent().get(1).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityRoleServiceTest method identityIdTest.
@Test
public void identityIdTest() {
IdmRoleDto role = testHelper.createRole();
IdmIdentityDto person = testHelper.createIdentity();
IdmIdentityRoleDto addRole = testHelper.createIdentityRole(person, role);
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(person.getId());
Page<IdmIdentityRoleDto> result = idmIdentityRoleService.find(filter, null);
assertEquals("Wrong RoleId", addRole.getId(), result.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithoutCheck.
@Test
public void testRemoveLastRuleWithoutCheck() {
String eavCode = "testingEav";
Long testEavIdentityValue = System.currentTimeMillis();
UUID testEavContractValue = 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.LONG);
testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.LONG);
IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.UUID);
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());
automaticRoleAttributeRuleService.delete(rule2);
// in this case we not able remove the last automatic role from identity
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testEmptyContract.
@Test
public void testEmptyContract() {
String testValue = "123!@#" + System.currentTimeMillis();
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, testValue);
//
IdmIdentityDto identity = testHelper.createIdentity();
//
// remove contract
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
identityContractService.delete(primeContract);
primeContract = identityContractService.getPrimeContract(identity.getId());
assertNull(primeContract);
//
identity.setDescription(testValue);
identity = identityService.save(identity);
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
// change value and recalculate
identity.setDescription(testValue + "-test");
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
// chnage back
identity.setDescription(testValue);
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
Aggregations