use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class InitTestData method init.
protected void init() {
// we are reusing demo data in tests as well
initDemoData.init();
//
securityService.setSystemAuthentication();
//
try {
IdmRoleDto superAdminRole = this.roleService.getByCode(InitApplicationData.ADMIN_ROLE);
IdmTreeNodeDto rootOrganization = treeNodeService.findRoots((UUID) null, new PageRequest(0, 1)).getContent().get(0);
//
if (!configurationService.getBooleanValue(PARAMETER_TEST_DATA_CREATED, false)) {
log.info("Creating test data ...");
//
IdmRoleDto role1 = new IdmRoleDto();
role1.setName(TEST_USER_ROLE);
role1 = this.roleService.save(role1);
log.info(MessageFormat.format("Test role created [id: {0}]", role1.getId()));
//
IdmRoleDto role2 = new IdmRoleDto();
role2.setName(TEST_CUSTOM_ROLE);
List<IdmRoleCompositionDto> subRoles = new ArrayList<>();
subRoles.add(new IdmRoleCompositionDto(role2.getId(), superAdminRole.getId()));
role2.setSubRoles(subRoles);
role2 = this.roleService.save(role2);
log.info(MessageFormat.format("Test role created [id: {0}]", role2.getId()));
//
// Users for JUnit testing
IdmIdentityDto testUser1 = new IdmIdentityDto();
testUser1.setUsername(TEST_USER_1);
testUser1.setPassword(new GuardedString("heslo"));
testUser1.setFirstName("Test");
testUser1.setLastName("First User");
testUser1.setEmail("test1@bscsolutions.eu");
testUser1 = this.identityService.save(testUser1);
log.info(MessageFormat.format("Identity created [id: {0}]", testUser1.getId()));
IdmIdentityDto testUser2 = new IdmIdentityDto();
testUser2.setUsername(TEST_USER_2);
testUser2.setPassword(new GuardedString("heslo"));
testUser2.setFirstName("Test");
testUser2.setLastName("Second User");
testUser2.setEmail("test2@bscsolutions.eu");
testUser2 = this.identityService.save(testUser2);
log.info(MessageFormat.format("Identity created [id: {0}]", testUser2.getId()));
IdmTreeTypeDto type = this.treeTypeService.get(rootOrganization.getTreeType());
IdmTreeNodeDto organization = new IdmTreeNodeDto();
organization.setCode("test");
organization.setName("Organization Test");
organization.setCreator("ja");
organization.setParent(rootOrganization.getId());
organization.setTreeType(type.getId());
organization = this.treeNodeService.save(organization);
IdmIdentityContractDto identityWorkPosition2 = new IdmIdentityContractDto();
identityWorkPosition2.setIdentity(testUser1.getId());
identityWorkPosition2.setWorkPosition(organization.getId());
identityWorkPosition2 = identityContractService.save(identityWorkPosition2);
IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
contractGuarantee.setIdentityContract(identityWorkPosition2.getId());
contractGuarantee.setGuarantee(testUser2.getId());
contractGuaranteeService.save(contractGuarantee);
//
log.info("Test data was created.");
//
configurationService.setBooleanValue(PARAMETER_TEST_DATA_CREATED, true);
}
//
} finally {
SecurityContextHolder.clearContext();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class SendNotificationToApplicantAndImplementerTest method createTestUser.
/**
* Creates testUser with working position and contract
*
* @return IdmIdentityDto
*/
private IdmIdentityDto createTestUser() {
IdmIdentityDto testUser = new IdmIdentityDto();
testUser.setUsername(getHelper().createName());
testUser.setPassword(new GuardedString(InitApplicationData.ADMIN_PASSWORD));
testUser.setFirstName("Test");
testUser.setLastName("User");
testUser.setEmail(testUser.getUsername() + "@bscsolutions.eu");
testUser = this.identityService.save(testUser);
IdmIdentityContractDto identityWorkPosition2 = new IdmIdentityContractDto();
identityWorkPosition2.setIdentity(testUser.getId());
identityWorkPosition2.setWorkPosition(organization.getId());
identityWorkPosition2 = identityContractService.save(identityWorkPosition2);
IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
contractGuarantee.setIdentityContract(identityWorkPosition2.getId());
contractGuarantee.setGuarantee(testUser2.getId());
contractGuaranteeService.save(contractGuarantee);
return testUser;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeByIdentityContractEvaluatorIntegrationTest method testCrud.
@Test
public void testCrud() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
IdmIdentityContractDto otherContract = getHelper().createContract(identity);
List<IdmContractGuaranteeDto> guarantees = null;
IdmRoleDto role = getHelper().createRole();
IdmContractGuaranteeDto guaranteeOne = getHelper().createContractGuarantee(primeContract, getHelper().createIdentity());
// other
getHelper().createContractGuarantee(otherContract.getId(), getHelper().createIdentity().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());
guarantees = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(guarantees.isEmpty());
} finally {
logout();
}
//
// without login
guarantees = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(guarantees.isEmpty());
//
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.CONTRACTGUARANTEE, IdmContractGuarantee.class, ContractGuaranteeByIdentityContractEvaluator.class);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// evaluate access
getHelper().login(identity.getUsername(), identity.getPassword());
guarantees = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, guarantees.size());
Assert.assertEquals(guaranteeOne.getId(), guarantees.get(0).getId());
//
Set<String> permissions = service.getPermissions(guaranteeOne);
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(guaranteeOne);
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.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testLinkAndUpdateContract.
@Test
public void testLinkAndUpdateContract() {
String position1 = "test-link-update-1-" + System.currentTimeMillis();
String position2 = "test-link-update-2-" + System.currentTimeMillis();
String position3 = "test-link-update-3-" + System.currentTimeMillis();
IdmIdentityDto leader = helper.createIdentity();
IdmTreeNodeDto workPosition = helper.createTreeNode();
SysSystemDto system = initData();
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
this.getBean().deleteAllResourceData();
config.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ENTITY);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
IdmIdentityDto identity1 = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityContractDto contrac1 = helper.getPrimeContract(identity1.getId());
IdmIdentityContractDto contrac2 = helper.getPrimeContract(identity2.getId());
IdmIdentityContractDto contrac3 = helper.getPrimeContract(identity3.getId());
contrac1.setPosition(position1);
contrac1.setDescription(position1);
contrac2.setPosition(position2);
contrac2.setDescription(position2);
contrac3.setPosition(position3);
contrac3.setDescription(position3);
contrac1 = contractService.save(contrac1);
contrac2 = contractService.save(contrac2);
contrac3 = contractService.save(contrac3);
// check empty guarantee
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contrac1.getId());
List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
guaranteeFilter.setIdentityContractId(contrac2.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
guaranteeFilter.setIdentityContractId(contrac3.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
assertNull(contrac1.getState());
assertNull(contrac2.getState());
assertNull(contrac3.getState());
this.getBean().createContractData(position1, identity1.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
this.getBean().createContractData(position2, identity2.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
this.getBean().createContractData(position3, identity3.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
// Start sync
helper.startSynchronization(config);
contractService.findAllByIdentity(identity1.getId());
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityContractDto updatedContract1 = helper.getPrimeContract(identity1.getId());
IdmIdentityContractDto updatedContract2 = helper.getPrimeContract(identity2.getId());
IdmIdentityContractDto updatedContract3 = helper.getPrimeContract(identity3.getId());
assertNotEquals(updatedContract1.getModified(), contrac1.getModified());
assertNotEquals(updatedContract2.getModified(), contrac2.getModified());
assertNotEquals(updatedContract3.getModified(), contrac3.getModified());
assertNotEquals(updatedContract1.getState(), contrac1.getState());
assertNotEquals(updatedContract2.getState(), contrac2.getState());
assertNotEquals(updatedContract3.getState(), contrac3.getState());
assertEquals(ContractState.EXCLUDED, updatedContract1.getState());
assertEquals(ContractState.EXCLUDED, updatedContract2.getState());
assertEquals(ContractState.EXCLUDED, updatedContract3.getState());
assertEquals(contrac1.getId(), updatedContract1.getId());
assertEquals(contrac2.getId(), updatedContract2.getId());
assertEquals(contrac3.getId(), updatedContract3.getId());
guaranteeFilter.setIdentityContractId(contrac1.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
guaranteeFilter.setIdentityContractId(contrac2.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
guaranteeFilter.setIdentityContractId(contrac3.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testDifferentSyncChangeGuarantee.
@Test
public void testDifferentSyncChangeGuarantee() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmIdentityDto defaultLeader = helper.createIdentity(CONTRACT_LEADER_TWO);
// Set default leader to sync configuration
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultLeader(defaultLeader.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// 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
// identity, so only ignore update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 3, OperationResultType.IGNORE);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractsOne.get(0).getId());
List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, gurantees.size());
IdmIdentityDto guarantee = DtoUtils.getEmbedded(gurantees.get(0), IdmContractGuarantee_.guarantee);
// Direct leader from resource
Assert.assertEquals(CONTRACT_LEADER_ONE, guarantee.getUsername());
guaranteeService.delete(gurantees.get(0));
// Start sync with enable different sync - guarantee was deleted
// so 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());
// Delete log
syncLogService.delete(log);
}
Aggregations