Search in sources :

Example 31 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testScriptThrowableWithCatch.

@Test
public void testScriptThrowableWithCatch() {
    String testString = "TEST-" + System.currentTimeMillis();
    // 
    Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> scripts = createThreeScripts();
    IdmScriptDto script1 = scripts.getFirst();
    IdmScriptDto script2 = scripts.getSecond();
    IdmScriptDto script3 = scripts.getThird();
    // 
    StringBuilder script1Body = new StringBuilder();
    script1Body.append("try {\n");
    script1Body.append(this.createScriptThatCallAnother(script2, IdmScriptCategory.DEFAULT, null, false));
    script1Body.append("} catch (Throwable e) {\n");
    script1Body.append("return \"" + testString + "\";\n");
    script1Body.append("}\n");
    script1Body.append("return null;\n");
    // 
    script1.setScript(script1Body.toString());
    script2.setScript(this.createScriptThatCallAnother(script3, IdmScriptCategory.DEFAULT, null, false));
    script3.setScript("throw new Throwable(\"" + testString + "\")");
    // 
    script1 = this.scriptService.save(script1);
    script2 = this.scriptService.save(script2);
    script3 = this.scriptService.save(script3);
    try {
        Object result = defaultScriptEvaluator.evaluate(script1.getCode());
        assertNotNull(result);
        assertEquals(testString, result);
    } catch (Throwable e) {
        fail();
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 32 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testThreeScriptAuthorityFailSecond.

@Test(expected = IdmSecurityException.class)
public void testThreeScriptAuthorityFailSecond() {
    IdmScriptDto third = new IdmScriptDto();
    third.setCategory(IdmScriptCategory.DEFAULT);
    third.setCode("script_name_" + System.currentTimeMillis());
    third.setName("script_name_" + System.currentTimeMillis());
    third.setScript(createTreeNodeScript());
    third = scriptService.save(third);
    createAuthority(third.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeNodeDto.class.getName(), null);
    // 
    IdmScriptDto second = new IdmScriptDto();
    second.setCategory(IdmScriptCategory.DEFAULT);
    second.setCode("script_name_" + System.currentTimeMillis());
    second.setName("script_name_" + System.currentTimeMillis());
    StringBuilder script = new StringBuilder(createTreeTypeScript());
    // security exception
    script.append(createTreeNodeScript());
    script.append(createScriptThatCallAnother(third, IdmScriptCategory.DEFAULT, null, false, null));
    second.setScript(script.toString());
    second = scriptService.save(second);
    createAuthority(second.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
    // 
    // 
    IdmScriptDto first = new IdmScriptDto();
    first.setCategory(IdmScriptCategory.DEFAULT);
    first.setCode("script_name_" + System.currentTimeMillis());
    first.setName("script_name_" + System.currentTimeMillis());
    script = new StringBuilder(createIdenityScript());
    script.append(createScriptThatCallAnother(second, IdmScriptCategory.DEFAULT, null, false, null));
    first.setScript(script.toString());
    first = scriptService.save(first);
    createAuthority(first.getId(), ScriptAuthorityType.CLASS_NAME, IdmIdentity.class.getName(), null);
    // 
    // 
    defaultScriptEvaluator.evaluate(first.getCode());
    fail();
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 33 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testEvaluateScriptWithCreateEntityAndWorkWith.

@Test(expected = IdmSecurityException.class)
public void testEvaluateScriptWithCreateEntityAndWorkWith() {
    IdmScriptDto subScript = new IdmScriptDto();
    subScript.setCategory(IdmScriptCategory.DEFAULT);
    subScript.setCode("script_name_" + System.currentTimeMillis());
    subScript.setName("script_name_" + System.currentTimeMillis());
    // 
    subScript.setScript(createTreeNodeScript(TREE_TYPE_CODE + "_2", TREE_TYPE_NAME + "_2"));
    // 
    subScript = scriptService.save(subScript);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.SERVICE, this.treeTypeService.getClass().getName(), "treeTypeService");
    // 
    IdmScriptDto parent = new IdmScriptDto();
    parent.setCategory(IdmScriptCategory.DEFAULT);
    parent.setCode("script_name_" + System.currentTimeMillis());
    parent.setName("script_name_" + System.currentTimeMillis());
    // 
    StringBuilder scriptToEnd = new StringBuilder();
    scriptToEnd.append("import eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto;\n");
    scriptToEnd.append("IdmTreeTypeDto entity = new IdmTreeTypeDto();\n");
    scriptToEnd.append("entity.setCode('" + TREE_TYPE_CODE + "_3');\n");
    scriptToEnd.append("entity.setName('" + TREE_TYPE_NAME + "_3');\n");
    scriptToEnd.append("return 'test';\n");
    // 
    parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, false, scriptToEnd.toString()));
    parent = scriptService.saveInternal(parent);
    // 
    groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
    // 
    fail();
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 34 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testEvaluateScriptWithCreateEntity.

@Test
public void testEvaluateScriptWithCreateEntity() {
    IdmScriptDto subScript = new IdmScriptDto();
    subScript.setCategory(IdmScriptCategory.DEFAULT);
    subScript.setCode("script_name_" + System.currentTimeMillis());
    subScript.setName("script_name_" + System.currentTimeMillis());
    // 
    subScript.setScript(createTreeNodeScript(TREE_TYPE_CODE, TREE_TYPE_NAME));
    // 
    subScript = scriptService.save(subScript);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.SERVICE, DefaultIdmTreeTypeService.class.getCanonicalName(), "treeTypeService");
    // 
    IdmScriptDto parent = new IdmScriptDto();
    parent.setCategory(IdmScriptCategory.DEFAULT);
    parent.setCode("script_name_" + System.currentTimeMillis());
    parent.setName("script_name_" + System.currentTimeMillis());
    // 
    parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, true));
    parent = scriptService.save(parent);
    // 
    Object uuid = groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
    // 
    assertNotNull(uuid);
    // 
    IdmTreeTypeDto treeType = this.treeTypeService.get(UUID.fromString(uuid.toString()));
    // 
    assertNotNull(treeType);
    assertEquals(this.TREE_TYPE_CODE, treeType.getCode());
    assertEquals(this.TREE_TYPE_NAME, treeType.getName());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) DefaultIdmTreeTypeService(eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeTypeService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 35 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testThreeScriptAuthoritySuccess.

@Test
public void testThreeScriptAuthoritySuccess() {
    IdmScriptDto third = new IdmScriptDto();
    third.setCategory(IdmScriptCategory.DEFAULT);
    third.setCode("third_script_name_" + System.currentTimeMillis());
    third.setName("third_script_name_" + System.currentTimeMillis());
    StringBuilder script = new StringBuilder();
    script.append(createRoleScript());
    script.append("return null;\n");
    third.setScript(script.toString());
    third = scriptService.save(third);
    createAuthority(third.getId(), ScriptAuthorityType.CLASS_NAME, IdmRole.class.getName(), null);
    // 
    IdmScriptDto second = new IdmScriptDto();
    second.setCategory(IdmScriptCategory.DEFAULT);
    second.setCode("second_script_name_" + System.currentTimeMillis());
    second.setName("second_script_name_" + System.currentTimeMillis());
    script = new StringBuilder();
    script.append(createTreeTypeScript());
    script.append(createScriptThatCallAnother(third, IdmScriptCategory.DEFAULT, null, false, null));
    script.append("return null;\n");
    second.setScript(script.toString());
    // 
    second = scriptService.save(second);
    createAuthority(second.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
    createAuthority(second.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeNodeDto.class.getName(), null);
    // 
    // 
    IdmScriptDto first = new IdmScriptDto();
    first.setCategory(IdmScriptCategory.DEFAULT);
    first.setCode("first_script_name_" + System.currentTimeMillis());
    first.setName("first_script_name_" + System.currentTimeMillis());
    script = new StringBuilder();
    script.append(createIdenityScript());
    script.append("\n");
    script.append(createRoleScript());
    script.append(createScriptThatCallAnother(second, IdmScriptCategory.DEFAULT, null, false, null));
    script.append("return null;\n");
    first.setScript(script.toString());
    first = scriptService.save(first);
    createAuthority(first.getId(), ScriptAuthorityType.CLASS_NAME, IdmIdentity.class.getName(), null);
    createAuthority(first.getId(), ScriptAuthorityType.CLASS_NAME, IdmRole.class.getName(), null);
    // 
    // 
    defaultScriptEvaluator.evaluate(first.getCode());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) 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