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