use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractPositionByIdentityContractEvaluatorIntegrationTest method testCrud.
@Test
public void testCrud() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
IdmIdentityContractDto otherContract = getHelper().createContract(identity);
List<IdmContractPositionDto> positions = null;
IdmRoleDto role = getHelper().createRole();
IdmContractPositionDto positionOne = getHelper().createContractPosition(primeContract.getId());
// other
getHelper().createContractPosition(otherContract.getId());
getHelper().createIdentityRole(identity, role);
getHelper().createUuidPolicy(role.getId(), primeContract.getId(), IdmBasePermission.READ);
// check - read without transient policy
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
Assert.assertEquals(primeContract.getId(), identityContractService.get(primeContract.getId(), IdmBasePermission.READ).getId());
positions = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(positions.isEmpty());
} finally {
logout();
}
//
// without login
positions = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(positions.isEmpty());
//
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.CONTRACTPOSITION, IdmContractPosition.class, ContractPositionByIdentityContractEvaluator.class);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// evaluate access
getHelper().login(identity.getUsername(), identity.getPassword());
positions = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals(positionOne.getId(), positions.get(0).getId());
//
Set<String> permissions = service.getPermissions(positionOne);
Assert.assertEquals(1, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
} finally {
logout();
}
//
getHelper().createUuidPolicy(role.getId(), primeContract.getId(), IdmBasePermission.UPDATE);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
Set<String> permissions = service.getPermissions(positionOne);
Assert.assertEquals(4, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.CREATE.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.DELETE.name())));
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method findByContractPosition.
@Test
public void findByContractPosition() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
IdmContractPositionDto contractPositionOne = getHelper().createContractPosition(contract);
IdmContractPositionDto contractPositionOther = getHelper().createContractPosition(contract);
IdmIdentityRoleDto one = getHelper().createIdentityRole(contractPositionOne, getHelper().createRole());
// other
getHelper().createIdentityRole(contractPositionOther, getHelper().createRole());
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
filter.setContractPositionId(contractPositionOne.getId());
List<IdmIdentityRoleDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(one.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class TreeTypeDeleteBulkActionIntegrationTest method testForceDelete.
@Test
public void testForceDelete() {
logout();
loginAsAdmin();
// create sub tree nodes, automatic roles, contract, contract positions, system mapping and sync
IdmTreeTypeDto treeType = getHelper().createTreeType();
SysSystemDto system = getHelper().createTestResourceSystem(true, getHelper().createName());
SysSystemMappingFilter filter = new SysSystemMappingFilter();
filter.setSystemId(system.getId());
SysSystemMappingDto mapping = systemMappingService.find(filter, null).getContent().get(0);
mapping.setTreeType(treeType.getId());
mapping = systemMappingService.save(mapping);
SysSyncConfigDto syncConfig = new SysSyncConfigDto();
syncConfig.setName(getHelper().createName());
syncConfig.setSystemMapping(mapping.getId());
// finds mapped attributes in existing system
SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
attributeFilter.setSystemId(system.getId());
attributeFilter.setName(TestHelper.ATTRIBUTE_MAPPING_NAME);
SysSystemAttributeMappingDto attribute = attributeMappingService.find(attributeFilter, null).getContent().get(0);
syncConfig.setCorrelationAttribute(attribute.getId());
syncConfig = (SysSyncConfigDto) syncService.save(syncConfig);
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleSystem(role, system);
//
IdmTreeNodeDto treeNode = getHelper().createTreeNode(treeType, null, null);
IdmTreeNodeDto subTreeNode = getHelper().createTreeNode(treeType, (String) null, treeNode);
IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode(treeType, (String) null, subTreeNode);
IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
//
// 3 manual, 2 automatic
Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
//
// remove tree type
Map<String, Object> properties = new HashMap<>();
properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
// delete by bulk action
IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeType.class, TreeTypeDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(treeType.getId()));
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, 0l, 0l);
//
Assert.assertNull(treeTypeService.get(treeType));
Assert.assertNull(treeNodeService.get(treeNode));
Assert.assertNull(treeNodeService.get(subTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
Assert.assertNull(identityContractService.get(contract).getWorkPosition());
Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
Assert.assertNull(roleTreeNodeService.get(automaticRole));
Assert.assertNull(systemMappingService.get(mapping));
Assert.assertNull(attributeMappingService.get(attribute));
Assert.assertNull(syncService.get(syncConfig));
//
Assert.assertNotNull(treeNodeService.get(otherTreeNode));
Assert.assertNotNull(getHelper().getPrimeContract(identity));
Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testContractPositions.
@Test
public void testContractPositions() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_THREE);
// Set default tree type to sync configuration
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Assert.assertNotNull(treeType);
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultTreeType(treeType.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
// Set work positions to resources
this.getBean().initContractPositionTest();
// Start sync again (we want to see some work positions)
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
IdmIdentityContractDto contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
//
IdmContractPositionFilter positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
List<IdmContractPositionDto> positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testDifferentSyncChangePositions.
@Test
public void testDifferentSyncChangePositions() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_THREE);
// Set default tree type to sync configuration
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Assert.assertNotNull(treeType);
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultTreeType(treeType.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
// Set work positions to resources
this.getBean().initContractPositionTest();
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
IdmIdentityContractDto contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
IdmContractPositionFilter positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
List<IdmContractPositionDto> positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Enable different sync.
config.setDifferentialSync(true);
config = syncConfigService.save(config);
Assert.assertTrue(config.isDifferentialSync());
// Start sync with enable different sync - no change was made on so only ignore update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 1, OperationResultType.IGNORE);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Delete position name
contractPositionService.delete(positions.get(0));
// Start sync with enable different sync - position name was changed, standard update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Delete log
syncLogService.delete(log);
}
Aggregations