use of org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager in project carbon-business-process by wso2.
the class BPMNOSGIService method getGroupIdentityManager.
public static BPSGroupIdentityManager getGroupIdentityManager() {
ProcessEngineImpl processEngine = (ProcessEngineImpl) getBPMNEngineService().getProcessEngine();
ProcessEngineConfigurationImpl processEngineConfigurationImpl = null;
if (processEngine != null) {
processEngineConfigurationImpl = processEngine.getProcessEngineConfiguration();
if (processEngineConfigurationImpl != null) {
BPSGroupIdentityManager bpsGroupIdentityManager = null;
if (processEngineConfigurationImpl.getSessionFactories() != null) {
BPSGroupManagerFactory bpsGroupManagerFactory = (BPSGroupManagerFactory) processEngineConfigurationImpl.getSessionFactories().get(GroupIdentityManager.class);
return (BPSGroupIdentityManager) bpsGroupManagerFactory.openSession();
}
}
}
throw new BPMNOSGIServiceException("Business Process Server Group manager couldn't be identified");
}
use of org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager in project carbon-business-process by wso2.
the class ProcessInstanceService method isValidUserToStartProcess.
private boolean isValidUserToStartProcess(ProcessInstanceCreateRequest processInstanceCreateRequest) {
// check whether the users/groups exist
String processDefinitionId = processInstanceCreateRequest.getProcessDefinitionId();
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
if (processDefinitionId == null) {
final String processDefinitionKey = processInstanceCreateRequest.getProcessDefinitionKey();
final String tenantId = processInstanceCreateRequest.getTenantId();
ProcessEngine processEngine = BPMNOSGIService.getBPMNEngineService().getProcessEngine();
if (processEngine != null) {
if (processDefinitionKey != null) {
if (((ProcessEngineImpl) processEngine).getProcessEngineConfiguration() != null) {
CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
if (commandExecutor != null) {
processDefinitionId = (String) commandExecutor.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
ProcessDefinitionEntityManager processDefinitionEntityManager = commandContext.getSession(ProcessDefinitionEntityManager.class);
ProcessDefinitionEntity processDefinitionEntity = processDefinitionEntityManager.findLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
if (processDefinitionEntity != null && processDefinitionEntity.getProcessDefinition() != null) {
return processDefinitionEntity.getProcessDefinition().getId();
}
return null;
}
});
}
}
if (processDefinitionId == null) {
return false;
}
}
String messageName = processInstanceCreateRequest.getMessage();
if (messageName != null && !messageName.isEmpty()) {
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().messageEventSubscriptionName(messageName);
if (processDefinitionQuery != null) {
processDefinitionQuery = processDefinitionQuery.processDefinitionTenantId(processInstanceCreateRequest.getTenantId());
if (processDefinitionQuery != null && processDefinitionQuery.count() > 1) {
processDefinitionQuery = processDefinitionQuery.latestVersion();
}
}
if (processDefinitionQuery != null) {
ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
if (processDefinition != null) {
processDefinitionId = processDefinition.getId();
}
}
if (processDefinitionId == null) {
return false;
}
}
}
}
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String userName = carbonContext.getUsername();
String tenantDomain = carbonContext.getTenantDomain();
String userNameWithTenantDomain = userName + "@" + tenantDomain;
BPSGroupIdentityManager bpsGroupIdentityManager = BPMNOSGIService.getGroupIdentityManager();
List<Group> groupList = bpsGroupIdentityManager.findGroupsByUser(userName);
List<IdentityLink> identityLinkList = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
boolean valueExistsForUserId = false;
boolean valueExistsForGroupId = false;
for (IdentityLink identityLink : identityLinkList) {
String userId = identityLink.getUserId();
if (userId != null) {
valueExistsForUserId = true;
if (userId.contains("$")) {
userId = resolveVariable(processInstanceCreateRequest, userId);
}
if (!userId.isEmpty() && (userId.equals(userName) || userId.equals(userNameWithTenantDomain))) {
return true;
}
continue;
}
String groupId = identityLink.getGroupId();
if (groupId != null) {
valueExistsForGroupId = true;
if (groupId.contains("$")) {
groupId = resolveVariable(processInstanceCreateRequest, groupId);
}
for (Group identityGroup : groupList) {
if (!groupId.isEmpty() && identityGroup.getId() != null && identityGroup.getId().equals(groupId)) {
return true;
}
}
}
}
if (!valueExistsForGroupId && !valueExistsForUserId) {
return true;
}
return false;
}
use of org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager in project carbon-business-process by wso2.
the class BPSGroupManagerFactory method openSession.
@Override
public Session openSession() {
try {
RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
UserStoreManager userStoreManager = registryService.getUserRealm(tenantId).getUserStoreManager();
BPSGroupIdentityManager bpsGroupIdentityManager = new BPSGroupIdentityManager(userStoreManager);
return bpsGroupIdentityManager;
} catch (Exception e) {
String msg = "Failed to obtain a group identity manager.";
log.error(msg, e);
return null;
}
}
Aggregations