use of eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptService method authorityTypeToDto.
/**
* Generate list of authorities from {@ IdmScriptType}
*
* @param type
* @return
*/
private List<IdmScriptAuthorityDto> authorityTypeToDto(IdmScriptType type, IdmScriptDto scriptDto) {
List<IdmScriptAuthorityDto> authorities = new ArrayList<>();
if (type.getAllowClasses() != null && type.getAllowClasses().getAllowClasses() != null) {
for (IdmScriptAllowClassType allowClass : type.getAllowClasses().getAllowClasses()) {
try {
Class.forName(allowClass.getClassName());
} catch (ClassNotFoundException e) {
LOG.error("Class [{}] isn't reachable, for script [{}] skip add this authority", allowClass.getClassName(), type.getCode(), e);
continue;
}
IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
authDto.setType(ScriptAuthorityType.CLASS_NAME);
authDto.setClassName(allowClass.getClassName());
authDto.setScript(scriptDto.getId());
authorities.add(authDto);
}
}
//
if (type.getServices() != null && type.getServices().getServices() != null) {
for (IdmScriptServiceType service : type.getServices().getServices()) {
if (scriptAuthorityService.isServiceReachable(service.getName(), service.getClassName())) {
IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
authDto.setType(ScriptAuthorityType.SERVICE);
authDto.setClassName(service.getClassName());
authDto.setService(service.getName());
authDto.setScript(scriptDto.getId());
authorities.add(authDto);
} else {
LOG.error("Service [{}] [{}] isn't reachable, for script [{}] skip add this authority", service.getName(), service.getClassName(), type.getCode());
continue;
}
}
}
//
return authorities;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testRemoveScriptWithAuthentization.
@Test
public void testRemoveScriptWithAuthentization() {
IdmScriptDto script = new IdmScriptDto();
script.setCategory(IdmScriptCategory.DEFAULT);
script.setCode("script_code_" + System.currentTimeMillis());
script.setName("script_name_" + System.currentTimeMillis());
//
script = scriptService.saveInternal(script);
IdmScriptAuthorityDto auth = createAuthority(script.getId(), ScriptAuthorityType.CLASS_NAME, List.class.getName(), null);
IdmScriptAuthorityDto auth2 = createAuthority(script.getId(), ScriptAuthorityType.CLASS_NAME, ArrayList.class.getName(), null);
//
scriptService.deleteInternal(script);
//
assertNull(scriptAuthorityService.get(auth.getId()));
assertNull(scriptAuthorityService.get(auth2.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method createAuthority.
/**
* Method create and save {@link IdmScriptAuthority} for script id fiven in paramete
* @param scriptId
* @param type
* @param className
* @param service
* @return
*/
private IdmScriptAuthorityDto createAuthority(UUID scriptId, ScriptAuthorityType type, String className, String service) {
IdmScriptAuthorityDto auth = new IdmScriptAuthorityDto();
auth.setClassName(className);
auth.setType(type);
auth.setScript(scriptId);
if (type == ScriptAuthorityType.SERVICE) {
auth.setService(service);
}
return scriptAuthorityService.saveInternal(auth);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptServiceIntegrationTest method removeAuthRedeploy.
@Test
public void removeAuthRedeploy() {
configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, TEST_BACKUP_FOLDER);
IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
assertNotNull(script1);
IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
filter.setScriptId(script1.getId());
List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, null).getContent();
assertEquals(4, authorities.size());
scriptAuthorityService.deleteAllByScript(script1.getId());
authorities = scriptAuthorityService.find(filter, null).getContent();
assertEquals(0, authorities.size());
scriptService.redeploy(script1);
authorities = scriptAuthorityService.find(filter, null).getContent();
assertEquals(4, authorities.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto 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());
}
Aggregations