use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class IdmScriptController method backup.
@ResponseBody
@RequestMapping(value = "/{backendId}/backup", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCRIPT_READ + "')")
@ApiOperation(value = "Backup script", nickname = "backupScript", response = IdmScriptDto.class, tags = { IdmScriptController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCRIPT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCRIPT_READ, description = "") }) }, notes = "Backup template to directory given in application properties.")
public ResponseEntity<?> backup(@ApiParam(value = "Script's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
IdmScriptDto script = service.get(backendId);
if (script == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, backendId);
}
service.backup(script);
return new ResponseEntity<>(toResource(script), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptService method typeToDto.
/**
* Transform type to dto, if second parameter is null it will be created new
* dto.
*
* @param type
* @param script
* @return
*/
private IdmScriptDto typeToDto(IdmScriptType type, IdmScriptDto script) {
if (script == null) {
script = new IdmScriptDto();
}
//
if (type == null) {
return script;
}
// transform type to DTO
script.setCode(type.getCode());
script.setName(type.getName());
script.setCategory(type.getCategory());
script.setScript(type.getBody());
script.setDescription(type.getDescription());
// attribute TYPE from IdmScriptType isn't implemented yet.
return script;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptService method init.
@Override
@Transactional
public void init() {
for (IdmScriptType scriptType : findScripts().values()) {
IdmScriptDto script = this.getByCode(scriptType.getCode());
// if script exist don't save it again => init only
if (script != null) {
LOG.info("Load script with code [{}], script is already initialized, skipping.", scriptType.getCode());
continue;
}
//
LOG.info("Load script with code [{}], script will be initialized.", scriptType.getCode());
// save script
script = this.save(typeToDto(scriptType, null));
// save authorities
this.scriptAuthorityService.saveAll(authorityTypeToDto(scriptType, script));
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ExecuteScriptTaskExecutorTest method testExecuteScriptSystem.
@Test
public void testExecuteScriptSystem() {
IdmScriptDto scriptDto = new IdmScriptDto();
scriptDto.setCode(TEST_SCRIPT_CODE + "_2");
scriptDto.setName(TEST_SCRIPT_CODE + "_2");
scriptDto.setCategory(IdmScriptCategory.SYSTEM);
StringBuilder builder = new StringBuilder();
builder.append("task.setCounter(0l);\n");
builder.append("task.setCount(10l);\n");
builder.append("for (int index = 0; index < 10; index++) {\n");
builder.append(" task.increaseCounter();\n");
builder.append(" task.updateState();\n");
builder.append("}\n");
scriptDto.setScript(builder.toString());
scriptDto = scriptService.save(scriptDto);
prepareAuthForTestScript(scriptDto);
Map<String, Object> parameters = new HashMap<>();
parameters.put("scriptCode", TEST_SCRIPT_CODE + "_2");
executeScriptEvaluator.init(parameters);
executeScriptEvaluator.process();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testScriptSecurityExceptionWithoutCatch.
@Test(expected = IdmSecurityException.class)
public void testScriptSecurityExceptionWithoutCatch() {
String testString = "TEST-" + System.currentTimeMillis();
//
Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> scripts = createThreeScripts();
IdmScriptDto script1 = scripts.getFirst();
IdmScriptDto script2 = scripts.getSecond();
IdmScriptDto script3 = scripts.getThird();
//
script1.setScript(this.createScriptThatCallAnother(script2, IdmScriptCategory.DEFAULT, null, false));
script2.setScript(this.createScriptThatCallAnother(script3, IdmScriptCategory.DEFAULT, null, false));
script3.setScript("throw new SecurityException(\"" + testString + "\")");
//
script1 = this.scriptService.save(script1);
script2 = this.scriptService.save(script2);
script3 = this.scriptService.save(script3);
// must throw exception
defaultScriptEvaluator.evaluate(script1.getCode());
fail();
}
Aggregations