2015-03-27 17:48:45.0|分类: activiti|浏览量: 3804
1、自定义的Activiti用户组管理器,主要重写对用户群组的增删改查等操作。 import java.util.ArrayList; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceException; import javax.persistence.Query; import org.activiti.engine.identity.Group; import org.activiti.engine.identity.GroupQuery; import org.activiti.engine.impl.GroupQueryImpl; import org.activiti.engine.impl.Page; import org.activiti.engine.impl.persistence.entity.GroupEntity; import org.activiti.engine.impl.persistence.entity.GroupManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; /** * 自定义的Activiti用户组管理器 * */ public class CustomGroupManager extends GroupManager { private static final Log logger = LogFactory .getLog(CustomGroupManager.class); @Override public GroupQuery createNewGroupQuery() { // TODO Auto-generated method stub return super.createNewGroupQuery(); } @Override public List findGroupByQueryCriteria(GroupQueryImpl query, Page page) { // TODO Auto-generated method stub return super.findGroupByQueryCriteria(query, page); } @Override public long findGroupCountByQueryCriteria(GroupQueryImpl query) { // TODO Auto-generated method stub return super.findGroupCountByQueryCriteria(query); } @Override public GroupEntity findGroupById(String groupId) { // TODO Auto-generated method stub return super.findGroupById(groupId); } @Override public List findGroupsByUser(String userId) { // TODO Auto-generated method stub return super.findGroupsByUser(userId); } @Override public List findPotentialStarterUsers(String proceDefId) { return super.findPotentialStarterUsers(proceDefId); } } 注意:如果想使用自己定义的用户组表,请重新这个findGroupById(final String groupCode)和findGroupsByUser(final String userCode),这两个方法是activiti查询的用户组的方法。 2、自定义的Activiti用户组会话工厂,返回类型不要变还是GroupManager,主要是覆盖系统默认添加的用户群组工厂。 import org.activiti.engine.impl.interceptor.Session; import org.activiti.engine.impl.interceptor.SessionFactory; import org.activiti.engine.impl.persistence.entity.GroupManager; import org.springframework.beans.factory.annotation.Autowired; /** * 自定义的Activiti用户组会话工厂 */ public class CustomGroupManagerFactory implements SessionFactory { private GroupManager groupManager; @Autowired public void setGroupManager(GroupManager groupManager) { this.groupManager = groupManager; } public Class getSessionType() { // 返回原始的GroupManager类型 return GroupManager.class; } public Session openSession() { // 返回自定义的GroupManager实例 return groupManager; } } 3、自定义的Activiti用户管理器, 主要重写对用户的增删改查等操作。 import java.util.List; import org.activiti.engine.identity.Group; import org.activiti.engine.identity.User; import org.activiti.engine.impl.Page; import org.activiti.engine.impl.UserQueryImpl; import org.activiti.engine.impl.persistence.entity.IdentityInfoEntity; import org.activiti.engine.impl.persistence.entity.UserEntity; import org.activiti.engine.impl.persistence.entity.UserManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * 自定义的Activiti用户管理器 */ public class CustomUserManager extends UserManager { private static final Log logger = LogFactory .getLog(CustomUserManager.class); @Override public UserEntity findUserById(String userId) { return super.findUserById(userId); } @Override public List findUserByQueryCriteria(UserQueryImpl query, Page page) { // TODO Auto-generated method stub return super.findUserByQueryCriteria(query, page); } @Override public long findUserCountByQueryCriteria(UserQueryImpl query) { // TODO Auto-generated method stub return super.findUserCountByQueryCriteria(query); } @Override public List findGroupsByUser(String userId) { // TODO Auto-generated method stub return super.findGroupsByUser(userId); } @Override public IdentityInfoEntity findUserInfoByUserIdAndKey(String userId, String key) { // TODO Auto-generated method stub return super.findUserInfoByUserIdAndKey(userId, key); } @Override public List findUserInfoKeysByUserIdAndType(String userId, String type) { // TODO Auto-generated method stub return super.findUserInfoKeysByUserIdAndType(userId, type); } @Override public Boolean checkPassword(String userId, String password) { // TODO Auto-generated method stub return super.checkPassword(userId, password); } @Override public List findPotentialStarterUsers(String proceDefId) { // TODO Auto-generated method stub return super.findPotentialStarterUsers(proceDefId); } } 注意:如果想使用自己定义的用户表,请重新这个findUserById(final String userCode)和findGroupsByUser(final String userCode),这两个方法是activiti查询的用户的方法 4、自定义的Activiti用户会话工厂, ,返回类型不要变还是 UserManager,主要是覆盖系统默认添加的用户工厂。 import org.activiti.engine.impl.interceptor.Session; import org.activiti.engine.impl.interceptor.SessionFactory; import org.activiti.engine.impl.persistence.entity.UserManager; import org.springframework.beans.factory.annotation.Autowired; /** * 自定义的Activiti用户会话工厂 */ public class CustomUserManagerFactory implements SessionFactory { private UserManager userManager; @Autowired public void setUserManager(UserManager userManager) { this.userManager = userManager; } public Class getSessionType() { // 返回原始的UserManager类型 return UserManager.class; } public Session openSession() { // 返回自定义的UserManager实例 return userManager; } } 5、activiti.cfg.xml相应的配置: |