Package org.huihoo.willow.client

Source Code of org.huihoo.willow.client.ServiceContextImpl

//----------------------------BEGIN LICENSE----------------------------
/*
* Willow : the Open Source WorkFlow Project
* Distributable under GNU LGPL license by gun.org
*
* Copyright (C) 2004-2010 huihoo.org
* Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com>
*
* ====================================================================
* Project Homepage : http://www.huihoo.org/willow
* Source Forge     : http://sourceforge.net/projects/huihoo
* Mailing list     : willow@lists.sourceforge.net
*/
//----------------------------END  LICENSE-----------------------------
package org.huihoo.willow.client;

import java.rmi.RemoteException;
import java.util.Vector;

import org.huihoo.willow.NamingServer;
import org.huihoo.willow.session.SessionManager;
import org.huihoo.willow.session.WillowSession;
import org.huihoo.workflow.client.serial.model.SerialService;
import org.huihoo.workflow.runtime.WorkflowService;
import org.huihoo.workflow.store.RealmDatabase;
import org.huihoo.workflow.store.UserDatabase;
import org.huihoo.workflow.usermodel.WorkflowParticipant;

/**
* @author reic
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ServiceContextImpl implements ServiceContext, java.io.Serializable
{
  private  transient NamingServer namingServer;
 
  public ServiceContextImpl(NamingServer namingServer) throws RemoteException
  {
    this.namingServer=namingServer;
  }

  public String  authenticate(String username,String password) throws RemoteException
  {      
    SessionManager manager = namingServer.getEngine().getSessionManager();
   
    WorkflowParticipant  participant=null;
   
    RealmDatabase  realmDatabase=namingServer.getEngine().getRealmDatabase();   
   
    participant=realmDatabase.authenticate(username,password);
    if(participant==null)
    {
      throw new RemoteException(
                "login engine unsuccessfully.username="
                  + username
                  + ",password="
                  + password);
    }
   
    WillowSession session=manager.createSession();
    session.setParticipant(participant);
   
    return session.getId();
  }
 
  public void      disconnect(String sessionID) throws RemoteException
  {
    SessionManager manager = namingServer.getEngine().getSessionManager();   
    WillowSession session=manager.findSession(sessionID);
   
    if(session!=null)
    {
      session.invalidate();
    }
  }
 
  public int   getMaxInactiveInterval(String sessionID)throws RemoteException
  {
    SessionManager manager = namingServer.getEngine().getSessionManager();   
    WillowSession session=manager.findSession(sessionID);
     
    if(session==null)
    {
      throw new RemoteException("Session invalid or expired");
    }

    return session.getMaxInactiveInterval();
  }
  public void  setMaxInactiveInterval(String sessionID,int interval)throws RemoteException
  {
    SessionManager manager = namingServer.getEngine().getSessionManager();   
    WillowSession session=manager.findSession(sessionID);
     
    if(session==null)
    {
      throw new RemoteException("Session invalid or expired");
    }

    session.setMaxInactiveInterval(interval);
  }
 
  public void   keepAlive(String sessionID) throws RemoteException
  {
    SessionManager manager = namingServer.getEngine().getSessionManager();   
    WillowSession session=manager.findSession(sessionID);
   
    if(session==null)
    {
      throw new RemoteException("Session invalid or expired");
    }
   
    if(session!=null)
    {
      session.access();
    }
  }
 
  public SerialService findService(
    String serviceName,
    String sessionID)
    throws RemoteException
  {   
    SessionManager manager = namingServer.getEngine().getSessionManager();   
    WillowSession session=manager.findSession(sessionID);
   
    if(session==null)
    {
      throw new RemoteException("Session invalid or expired");
    }   
   
   
    WorkflowParticipant participant=session.getParticipant();
    String userid=participant.getUUID();
    String password=participant.getPassword();
   
    SerialService liveService = null;
   
    WorkflowService workflowService=namingServer.findWorkflowService(serviceName);
   
    if (workflowService != null)
    {
      if (!authenticate(workflowService, userid, password))
      {
        throw new RemoteException("login WorkflowService unsuccessfully.userid="+ userid+ ",password="+ password);
      }
    }

    return new SerialServiceImpl(workflowService);
  }

  public SerialService[] findServices(String sessionID)
    throws RemoteException
  {
    SessionManager manager = namingServer.getEngine().getSessionManager();   
    WillowSession session=manager.findSession(sessionID);
   
    if(session==null)
    {
      throw new RemoteException("Session invalid or expired");
    }   
   
   
    WorkflowParticipant participant=session.getParticipant();
    String userid=participant.getUUID();
    String password=participant.getPassword();
   
    Vector vector = new Vector(0);

    WorkflowService[] services=namingServer.findWorkflowServices();
    for (int i = 0; i < services.length; ++i)
    {               
      WorkflowService temp=services[i];
      if (authenticate(temp, userid, password))
      {
        vector.add(new SerialServiceImpl(temp));
      }
    }
   
    int size=vector.size();
    SerialService[] result=new SerialService[size];
    for(int i=0;i<size;++i)
    {
      result[i]=(SerialService)vector.elementAt(i);
    }
    return result;
  }
 
  //-----------------------------------------------------------------------------

  private boolean authenticate(
    WorkflowService workflowService,
    String userid,
    String password)
    throws RemoteException
  {
   
    UserDatabase userDatabase = workflowService.getUserDatabase();

    WorkflowParticipant user = userDatabase.findParticipant(userid);

    if (user != null && user.getPassword().equals(password))
    {
      return true;
    }

    return false;
  }
}
TOP

Related Classes of org.huihoo.willow.client.ServiceContextImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.