之前做一个基于JBPM4.4的工作流系统,当中涉及到工作流中的人员与原有系统组织人员的整合的工作,通过实现IdentitySession接口来完成调用现有系统的人员和组代码如下
最近新的系统中考虑用Jbpm的升级版本Activiti,因为activiti的底层不再依赖hibernate,可以更加灵活的使用,并且也完美支持BPMN2.0协议。在新系统开发中也遇到了与系统的组织人员集成的问题,抛弃系统自带的Act_ID_XXX,使用系统自己的组织人员权限控制组件。
因为 Activiti是在jbpm4.X的基础上发展而来的,而Jbpm4.4是支持这种扩展的,所以想Tom baeyens没有那么傻吧。于是搜索 Activiti IdentitySession。发现竟然在5.8版本里已经被舍弃了!!!后来又在网上找,看了几种方法大致有 在自己的业务系统人员组织的CRUD代码中同步执行到ACT-ID-*表中,还有就是自己实现IdentityService接口。
从http://nanquan.iteye.com/blog/1544146
文章中我们可以学到一些调用其他认证方法的解决思路 参考这篇文章我们可以修改下完成与实现自有系统用户体系的用户与审批组
1,MyUserManager/MyGroupManager extends UserManager/GroupManager 2,MyUserManagerFactory/MyGroupManagerFactory implements SessionFactory import com.tds.activit.impl.MyUserManager; public class MyUserManagerFactory implements SessionFactory { @Override public Class<?> getSessionType() { return UserManager.class; } @Override public Session openSession() { return new MyUserManager(); } } import com.tds.activit.impl.MyGroupManager; public class MyGroupManagerFactory implements SessionFactory{ @Override public Class<?> getSessionType() { return GroupManager.class; } @Override public Session openSession() { return new MyGroupManager(); } }
3,注入processEngineConfiguration <property name="customSessionFactories"> <list> <bean class="org.activiti.examples.my.factorys.MyUserManagerFactory" /> <bean class="org.activiti.examples.my.factorys.MyGroupManagerFactory" /> </list> </property>
public class UserSession implements IdentitySession { private UserService userService = (UserService) SpringContextHolder.getBean("userService"); private OrgnationService orgnationService = (OrgnationService) SpringContextHolder.getBean("orgnationService"); private ApproverGroupService approverGroupService = (ApproverGroupService) SpringContextHolder.getBean("approverGroupService"); // ---------------------------------methods above are not need overwrite-------------------------------------------- @Override public Group findGroupById(String groupId) { return approverGroupService.get(new Long(groupId)); } @Override public List<Group> findGroupsByUser(String userId) { // cn.com.todaysoft.oa.domain.org.User user = userService.get(new Long(userId)); cn.com.todaysoft.oa.domain.org.User user = orgnationService.getUser(new Long(userId)); List<Group> list = new ArrayList<Group>(); Iterator it = user.getApproverGroups().iterator(); while (it.hasNext()) { list.add((Group) it.next()); } return list; } @Override public List<Group> findGroupsByUserAndGroupType(String userId, String groupType) { return findGroupsByUser(userId); } @Override public User findUserById(String userId) { return userService.get(new Long(userId)); } @Override public List<User> findUsers() { List<cn.com.todaysoft.oa.domain.org.User> userList = userService.getAll(); List<User> list = new ArrayList<User>(); for (User user : userList) { list.add((User) user); } return list; } @Override public List<User> findUsersByGroup(String groupId) { List<cn.com.todaysoft.oa.domain.org.User> userList = userService.findByGroupId(new Long(groupId)); List<User> list = new ArrayList<User>(); for (User user : userList) { list.add((User) user); } return list; } @Override public List<User> findUsersById(String... userIds) { // TODO Auto-generated method stub return null; } }