Search in sources :

Example 6 with IdmScriptDto

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

the class ScriptEvaluatorTest method createThreeScripts.

/**
 * Method create three unique script with same code and name. Script body isn't filled.
 *
 * @return
 */
private Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> createThreeScripts() {
    String codeName1 = "script_name_" + System.currentTimeMillis();
    IdmScriptDto script1 = new IdmScriptDto();
    script1.setCategory(IdmScriptCategory.DEFAULT);
    script1.setCode(codeName1);
    script1.setName(codeName1);
    script1 = this.scriptService.save(script1);
    // 
    String codeName2 = "script_name_" + System.currentTimeMillis();
    IdmScriptDto script2 = new IdmScriptDto();
    script2.setCategory(IdmScriptCategory.DEFAULT);
    script2.setCode(codeName2);
    script2.setName(codeName2);
    script2 = this.scriptService.save(script2);
    // 
    String codeName3 = "script_name_" + System.currentTimeMillis();
    IdmScriptDto script3 = new IdmScriptDto();
    script3.setCategory(IdmScriptCategory.DEFAULT);
    script3.setCode(codeName3);
    script3.setName(codeName3);
    script3 = this.scriptService.save(script3);
    // 
    return new Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto>(script1, script2, script3);
}
Also used : Triple(org.hibernate.envers.internal.tools.Triple) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)

Example 7 with IdmScriptDto

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

Example 8 with IdmScriptDto

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

the class ScriptEvaluatorTest method testScriptRuntimeExceptionWithoutCatch.

@Test
public void testScriptRuntimeExceptionWithoutCatch() {
    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 RuntimeException(\"" + testString + "\")");
    // 
    script1 = this.scriptService.save(script1);
    script2 = this.scriptService.save(script2);
    script3 = this.scriptService.save(script3);
    try {
        // must throw exception
        defaultScriptEvaluator.evaluate(script1.getCode());
        fail();
    } catch (Throwable e) {
        assertTrue(e instanceof RuntimeException);
        assertTrue(e.getMessage().contains(testString));
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with IdmScriptDto

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

the class ScriptEvaluatorTest method testScriptSecurityExceptionWithCatch.

@Test
public void testScriptSecurityExceptionWithCatch() {
    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 SecurityException(\"" + testString + "\")");
    // 
    script1 = this.scriptService.save(script1);
    script2 = this.scriptService.save(script2);
    script3 = this.scriptService.save(script3);
    // 
    try {
        // try catch SecurityException but propage this exception as throwable, this is possible
        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 10 with IdmScriptDto

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

the class ScriptEvaluatorTest method testEvaluateScriptWithAuth.

@Test
public void testEvaluateScriptWithAuth() {
    IdmScriptDto subScript = new IdmScriptDto();
    subScript.setCategory(IdmScriptCategory.DEFAULT);
    subScript.setCode("script_name_" + System.currentTimeMillis());
    subScript.setName("script_name_" + System.currentTimeMillis());
    // 
    subScript.setScript(createListScript(Boolean.TRUE));
    // 
    subScript = scriptService.saveInternal(subScript);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmRole.class.getName(), null);
    // 
    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, false));
    parent = scriptService.saveInternal(parent);
    // 
    groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) 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