use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class UsernameIdentityFilterBuilderIntegrationTest method testFindIdentityByUuid.
@Test
public void testFindIdentityByUuid() {
// prepare data
IdmIdentityDto identityOne = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
UsernameIdentityFilter identityFilter = new UsernameIdentityFilter(repository);
//
IdmIdentityFilter dataFilter = new IdmIdentityFilter();
dataFilter.setUsername(identityOne.getUsername());
List<IdmIdentity> identities = identityFilter.find(dataFilter, null).getContent();
//
assertEquals(1, identities.size());
assertEquals(identityOne.getId(), identities.get(0).getId());
//
dataFilter.setUsername(identityTwo.getUsername());
identities = identityFilter.find(dataFilter, null).getContent();
assertEquals(1, identities.size());
assertEquals(identityTwo.getId(), identities.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testSynchronizationCache.
@Test
public void testSynchronizationCache() {
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String userOne = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(userOne, testFirstName, testLastName);
String userTwo = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(userTwo, testFirstName, testLastName);
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setEntityType(SystemEntityType.IDENTITY);
mappingFilter.setSystemId(system.getId());
mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto defaultMapping = mappings.get(0);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(defaultMapping.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
return attribute.getIdmPropertyName().equals(IdmIdentity_.firstName.getName());
}).findFirst().orElse(null);
Assert.assertNotNull(firstNameAttribute);
StringBuilder scriptGenerateUuid = new StringBuilder();
scriptGenerateUuid.append("import java.util.UUID;");
scriptGenerateUuid.append(System.lineSeparator());
scriptGenerateUuid.append("return UUID.randomUUID();");
String scriptName = "generateUuid";
IdmScriptDto scriptUuid = new IdmScriptDto();
scriptUuid.setCategory(IdmScriptCategory.TRANSFORM_FROM);
scriptUuid.setCode(scriptName);
scriptUuid.setName(scriptName);
scriptUuid.setScript(scriptGenerateUuid.toString());
scriptUuid = scriptService.save(scriptUuid);
IdmScriptAuthorityDto scriptAuth = new IdmScriptAuthorityDto();
scriptAuth.setClassName("java.util.UUID");
scriptAuth.setType(ScriptAuthorityType.CLASS_NAME);
scriptAuth.setScript(scriptUuid.getId());
scriptAuth = scriptAuthrotityService.save(scriptAuth);
// we must call script
StringBuilder transformationScript = new StringBuilder();
transformationScript.append("return scriptEvaluator.evaluate(");
transformationScript.append(System.lineSeparator());
transformationScript.append("scriptEvaluator.newBuilder()");
transformationScript.append(System.lineSeparator());
transformationScript.append(".setScriptCode('" + scriptName + "')");
transformationScript.append(System.lineSeparator());
transformationScript.append(".build());");
transformationScript.append(System.lineSeparator());
firstNameAttribute.setTransformFromResourceScript(transformationScript.toString());
firstNameAttribute.setCached(true);
firstNameAttribute = schemaAttributeMappingService.save(firstNameAttribute);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setLastName(testLastName);
List<IdmIdentityDto> identities = identityService.find(filter, null).getContent();
assertEquals(2, identities.size());
//
IdmIdentityDto identityOne = identities.get(0);
IdmIdentityDto identityTwo = identities.get(1);
//
assertNotEquals(identityOne.getFirstName(), identityTwo.getFirstName());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method updateIdentityWithInvalidContractTest.
@Test
public void updateIdentityWithInvalidContractTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
IdmIdentityDto identityOne = helper.createIdentity(IDENTITY_ONE);
IdmIdentityContractDto primeContract = contractService.getPrimeContract(identityOne.getId());
Assert.assertNotNull(primeContract);
primeContract.setValidTill(LocalDate.now().minusDays(10));
primeContract = contractService.save(primeContract);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(IDENTITY_ONE);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK, 1, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identityOne.getId());
Assert.assertEquals(0, roles.size());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class SubordinatesEvaluator method getPredicate.
@Override
public Predicate getPredicate(Root<IdmIdentity> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
if (!hasPermission(policy, permission)) {
return null;
}
if (!securityService.isAuthenticated()) {
return null;
}
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setSubordinatesFor(securityService.getAuthentication().getCurrentIdentity().getId());
return filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR).getPredicate(root, query, builder, filter);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class SubordinatesEvaluator method getPermissions.
@Override
public Set<String> getPermissions(IdmIdentity entity, AuthorizationPolicy policy) {
Set<String> permissions = super.getPermissions(entity, policy);
if (entity == null || !securityService.isAuthenticated()) {
return permissions;
}
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setManagersFor(entity.getId());
boolean isManager = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_MANAGERS_FOR).find(filter, null).getContent().stream().anyMatch(identity -> {
return identity.getUsername().equals(securityService.getUsername());
});
if (isManager) {
permissions.addAll(policy.getPermissions());
}
return permissions;
}
Aggregations