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();
}
}
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();
}
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();
}
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());
}
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());
}
Aggregations