Search in sources :

Example 1 with SecurityManager

use of org.kie.internal.runtime.manager.SecurityManager in project jbpm by kiegroup.

the class SecurityManagerTest method testDenyAllSecurityManager.

@Test(expected = SecurityException.class)
public void testDenyAllSecurityManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    ((InternalRuntimeManager) manager).setSecurityManager(new SecurityManager() {

        @Override
        public void checkPermission() throws SecurityException {
            throw new SecurityException("Deny all on purpose");
        }
    });
    manager.getRuntimeEngine(EmptyContext.get());
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) SecurityManager(org.kie.internal.runtime.manager.SecurityManager) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with SecurityManager

use of org.kie.internal.runtime.manager.SecurityManager in project jbpm by kiegroup.

the class SecurityManagerTest method testCustomSecurityManager.

@Test(expected = SecurityException.class)
public void testCustomSecurityManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    final User user = new User("john");
    ((InternalRuntimeManager) manager).setSecurityManager(new SecurityManager() {

        @Override
        public void checkPermission() throws SecurityException {
            if ("mary".equals(user.getName())) {
                throw new SecurityException("Mary is not allowed to use runtime manager");
            }
        }
    });
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(runtime);
    manager.disposeRuntimeEngine(runtime);
    user.setName("mary");
    manager.getRuntimeEngine(EmptyContext.get());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) SecurityManager(org.kie.internal.runtime.manager.SecurityManager) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)2 Test (org.junit.Test)2 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)2 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)2 SecurityManager (org.kie.internal.runtime.manager.SecurityManager)2 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1