Search in sources :

Example 1 with IdentityRolesSecurityManager

use of org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager in project jbpm by kiegroup.

the class AbstractDeploymentService method commonDeploy.

public void commonDeploy(DeploymentUnit unit, DeployedUnitImpl deployedUnit, RuntimeEnvironment environemnt, KieContainer kieContainer) {
    synchronized (this) {
        if (deploymentsMap.containsKey(unit.getIdentifier())) {
            DeployedUnit deployed = deploymentsMap.remove(unit.getIdentifier());
            RuntimeManager manager = deployed.getRuntimeManager();
            manager.close();
        }
        RuntimeManager manager = null;
        deploymentsMap.put(unit.getIdentifier(), deployedUnit);
        ((SimpleRuntimeEnvironment) environemnt).addToEnvironment("IdentityProvider", identityProvider);
        ((SimpleRuntimeEnvironment) environemnt).addToEnvironment("Active", deployedUnit.isActive());
        try {
            switch(unit.getStrategy()) {
                case SINGLETON:
                    manager = managerFactory.newSingletonRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                case PER_REQUEST:
                    manager = managerFactory.newPerRequestRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                case PER_PROCESS_INSTANCE:
                    manager = managerFactory.newPerProcessInstanceRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                case PER_CASE:
                    manager = managerFactory.newPerCaseRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                default:
                    throw new IllegalArgumentException("Invalid strategy " + unit.getStrategy());
            }
            if (!deployedUnit.isActive()) {
                ((InternalRuntimeManager) manager).deactivate();
            }
            ((InternalRuntimeManager) manager).setKieContainer(kieContainer);
            deployedUnit.setRuntimeManager(manager);
            DeploymentDescriptor descriptor = ((InternalRuntimeManager) manager).getDeploymentDescriptor();
            List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_EXECUTE);
            if (requiredRoles != null && !requiredRoles.isEmpty()) {
                ((InternalRuntimeManager) manager).setSecurityManager(new IdentityRolesSecurityManager(identityProvider, requiredRoles));
            }
            notifyOnDeploy(unit, deployedUnit);
        } catch (Throwable e) {
            deploymentsMap.remove(unit.getIdentifier());
            if (manager != null) {
                manager.close();
            }
            notifyOnUnDeploy(unit, deployedUnit);
            throw new RuntimeException(e);
        }
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) IdentityRolesSecurityManager(org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Aggregations

IdentityRolesSecurityManager (org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager)1 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)1 SimpleRuntimeEnvironment (org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment)1 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1