Search in sources :

Example 36 with IdmScriptDto

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

the class ScriptEvaluatorTest method testCreateDuplScriptName.

@Test
public void testCreateDuplScriptName() {
    String duplName = "script_name";
    // 
    IdmScriptDto script = new IdmScriptDto();
    script.setCategory(IdmScriptCategory.DEFAULT);
    script.setCode("script_code_" + System.currentTimeMillis());
    script.setName(duplName);
    // 
    script = scriptService.saveInternal(script);
    // 
    IdmScriptDto script2 = new IdmScriptDto();
    script2.setCategory(IdmScriptCategory.DEFAULT);
    script2.setCode("script_code_" + System.currentTimeMillis());
    script2.setName(duplName);
    // 
    script2 = scriptService.saveInternal(script2);
    // 
    assertNotEquals(script.getCode(), script2.getCode());
    assertEquals(script.getName(), script2.getName());
    assertEquals(script.getCategory(), script2.getCategory());
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 37 with IdmScriptDto

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

the class ScriptEvaluatorTest method testThreeScriptAuthorityThirdScriptUseAnotherAuth.

@Test(expected = IdmSecurityException.class)
public void testThreeScriptAuthorityThirdScriptUseAnotherAuth() {
    IdmScriptDto third = new IdmScriptDto();
    third.setCategory(IdmScriptCategory.DEFAULT);
    third.setCode("script_name_" + System.currentTimeMillis());
    third.setName("script_name_" + System.currentTimeMillis());
    StringBuilder script = new StringBuilder(createTreeNodeScript());
    // fail
    script.append(createIdenityScript());
    third.setScript(script.toString());
    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());
    script = new StringBuilder(createTreeTypeScript());
    script.append(createTreeNodeScript());
    second.setScript(createScriptThatCallAnother(third, IdmScriptCategory.DEFAULT, null, false, null));
    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 38 with IdmScriptDto

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

the class ScriptEvaluatorTest method testEvaluateScriptWithoutAuth.

@Test(expected = IdmSecurityException.class)
public void testEvaluateScriptWithoutAuth() {
    IdmScriptDto script = new IdmScriptDto();
    script.setCategory(IdmScriptCategory.DEFAULT);
    script.setCode("script_name_" + System.currentTimeMillis());
    script.setName("script_name_" + System.currentTimeMillis());
    // 
    script.setScript(createListScript(Boolean.TRUE));
    // 
    script = scriptService.saveInternal(script);
    // 
    IdmScriptDto script2 = new IdmScriptDto();
    script2.setCategory(IdmScriptCategory.DEFAULT);
    script2.setCode("script_name_" + System.currentTimeMillis());
    script2.setName("script_name_" + System.currentTimeMillis());
    // 
    script.setScript(createScriptThatCallAnother(script, IdmScriptCategory.DEFAULT, null, false));
    // 
    script2 = scriptService.saveInternal(script2);
    // 
    groovyScriptService.evaluate(script.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 39 with IdmScriptDto

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

the class ScriptEvaluatorTest method testScriptExceptionWithoutCatch.

@Test
public void testScriptExceptionWithoutCatch() {
    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 Exception(\"" + 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 ResultCodeException);
        assertTrue(e.getMessage().contains(testString));
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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