Search in sources :

Example 1 with IdmScriptDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IdmScriptDto

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;
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)

Example 3 with IdmScriptDto

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));
    }
}
Also used : IdmScriptType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmScriptDto

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();
}
Also used : HashMap(java.util.HashMap) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with IdmScriptDto

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();
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmScriptDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)39 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 Test (org.junit.Test)34 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)5 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)5 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)3 HashMap (java.util.HashMap)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)2 IdmScriptAuthorityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ResponseEntity (org.springframework.http.ResponseEntity)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1