AnsweredAssumed Answered

How can I custom user with spring boot

Question asked by chriszhang on May 15, 2016
Latest reply on May 18, 2016 by jbarrez
when I custom  activiti user with spring mvc,it work well.I move it to spring boot,does't work.

——————-CustomGroupManagerFactory—————-
public class CustomGroupManagerFactory implements SessionFactory {
   
   private CustomGroupEntityManager customGroupEntityManager;

   public void setCustomGroupEntityManager(CustomGroupEntityManager customGroupEntityManager) {
      this.customGroupEntityManager = customGroupEntityManager;
   }
   
   public Class<?> getSessionType() {
      //return GroupEntityManager.class;
      return GroupIdentityManager.class;
   }

   public Session openSession() {
      return customGroupEntityManager;
   }
}
——————-CustomGroupEntityManager———————
public class CustomGroupEntityManager extends GroupEntityManager {
   
    @Override 
    public Group createNewGroup(String groupId) { 
       throw new RuntimeException("not implement method.");  
    } 
 
    @Override 
    public void insertGroup(Group group) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public void updateGroup(Group updatedGroup) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public void deleteGroup(String groupId) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public GroupQuery createNewGroupQuery() { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page) { 
       throw new RuntimeException("not implement method.");
    } 
 
    @Override 
    public long findGroupCountByQueryCriteria(GroupQueryImpl query) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public List<Group> findGroupsByUser(String userId) { 
        if(userId == null){
           return null;
        }
        List<Group> groups = new ArrayList<Group>();
        return groups;
    } 
 
    @Override 
    public List<Group> findGroupsByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults) { 
       throw new RuntimeException("not implement method.");  
    } 
 
    @Override 
    public long findGroupCountByNativeQuery(Map<String, Object> parameterMap) { 
       throw new RuntimeException("not implement method.");  
    }

———————-CustomUserManagerFactory———————–

public class CustomUserManagerFactory implements SessionFactory { 
   private CustomUserEntityManager customUserEntityManager;   
      
    public void setCustomUserEntityManager(CustomUserEntityManager customUserEntityManager) {
      this.customUserEntityManager = customUserEntityManager;
   }

   public Class<?> getSessionType() {   
        return UserIdentityManager.class;   
    }   
   
   

   public Session openSession() {   
        return customUserEntityManager;   
    }   


————–CustomUserEntityManager ————-

public class CustomUserEntityManager extends UserEntityManager { 
 
    @Override 
    public User createNewUser(String userId) { 
        throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public void insertUser(User user) { 
       throw new RuntimeException("not implement method.");
    } 
 
    @Override 
    public void updateUser(User updatedUser) { 
       throw new RuntimeException("not implement method.");
    } 
 
    @Override 
    public UserEntity findUserById(String userId) { 
        UserEntity userEntity = new UserEntity();
       
        /*com.gf.activiti.model.User user= userService.findByUserId(userId);
       
        userEntity.setRevision(1);
        userEntity.setId(user.getUserId());
        userEntity.setFirstName(user.getName());
        userEntity.setPassword(user.getPassword());
        userEntity.setEmail(user.getEmail());*/
       
        userEntity.setRevision(1);
        userEntity.setId("22562");
        userEntity.setFirstName("zhangshengbing");
        userEntity.setPassword("123123");
        userEntity.setEmail("zhangshengbing@gf.com.cn");
       
        return userEntity;
    } 
 
    @Override 
    public void deleteUser(String userId) { 
       throw new RuntimeException("not implement method.");  
    } 
 
    @Override 
    public List<User> findUserByQueryCriteria(UserQueryImpl query, Page page) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public long findUserCountByQueryCriteria(UserQueryImpl query) { 
       throw new RuntimeException("not implement method.");  
    } 
 
    @Override 
    public List<Group> findGroupsByUser(String userId) { 
        if(userId == null){
           return null;
        }
       
        /*Set<Role> roles = userService.findByUserId(userId).getRoles();
        List<Role> groupList = new ArrayList<Role>();
        groupList.addAll(roles);//ȥ��
        List<Group> groups = new ArrayList<Group>();
        GroupEntity groupEntity;
        String roleId;
       
        for(Role role: groupList){
           groupEntity = new GroupEntity();
           groupEntity.setRevision(1);
           groupEntity.setType("assignment");
           roleId = String.valueOf(role.getRoleId());
           groupEntity.setId(roleId);
           groupEntity.setName(role.getRoleName());
           groups.add(groupEntity);
        }*/
        List<Group> groups = new ArrayList<Group>();
        GroupEntity groupEntity;
        groupEntity = new GroupEntity();
       groupEntity.setRevision(1);
       groupEntity.setType("assignment");
       groupEntity.setId("1");
       groupEntity.setName("��������Ա");
       groups.add(groupEntity);
        return groups;
    } 
 
    @Override 
    public UserQuery createNewUserQuery() { 
       throw new RuntimeException("not implement method.");
    } 
 
    @Override 
    public IdentityInfoEntity findUserInfoByUserIdAndKey(String userId, String key) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public List<String> findUserInfoKeysByUserIdAndType(String userId, String type) { 
       throw new RuntimeException("not implement method.");  
    } 
 
    @Override 
    public Boolean checkPassword(String userId, String password) { 
       System.out.println("———————————————-userId:"+userId+",password:"+password);
       return true;
    } 
 
    @Override 
    public List<User> findPotentialStarterUsers(String proceDefId) { 
       throw new RuntimeException("not implement method."); 
    } 
 
    @Override 
    public List<User> findUsersByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults) { 
       throw new RuntimeException("not implement method.");  
    } 
 
    @Override 
    public long findUserCountByNativeQuery(Map<String, Object> parameterMap) { 
       throw new RuntimeException("not implement method."); 
    } 
 

———————-activiti.cfg.xml————————

<bean id="processEngineConfiguration"
      class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
      <property name="jdbcUrl"
         value="jdbc:h2:file:~/activiti-in-action-chapter6;AUTO_SERVER=TRUE" />
      <property name="jdbcDriver" value="org.h2.Driver" />
      <property name="jdbcUsername" value="sa" />
      <property name="jdbcPassword" value="" />

      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="false" />
      <property name="activityFontName" value="宋体" />
      <property name="labelFontName" value="宋体" />

      <property name="customSessionFactories">
         <list>
            <bean class="com.gf.activiti.manager.CustomGroupManagerFactory">
               <property name="customGroupEntityManager">
                  <bean class="com.gf.activiti.manager.CustomGroupEntityManager"></bean>
               </property>
            </bean>
            <bean class="com.gf.activiti.manager.CustomUserManagerFactory">
               <property name="customUserEntityManager">
                  <bean class="com.gf.activiti.manager.CustomUserEntityManager"></bean>
               </property>
            </bean>
         </list>
      </property>
   </bean>

Outcomes