Ejemplo n.º 1
0
/**
 * \brief Function to reconnect the session
 * \param user The object which manipulates user information
 * \param host The object which manipulates client machine information
 * \param sessionId The session identifier
 * \return raises an exception on error
 */
int
SessionServer::reconnect(UserServer user, MachineClientServer clientMachineServer,
                         std::string sessionId) {
  msession.setSessionId(sessionId);

  if (! user.isAuthenticate()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
  }

  int state = getState(true);
  if (state < 0) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_SESSION_ID);
  }

  if (state != vishnu::SESSION_ACTIVE) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_SESSION_ID);
  }

  int existSessionKey = getSessionkey(clientMachineServer.getId(),
                                      user.getNumUserFromLoginInfo(user.getData().getUserId(),user.getData().getPassword()),
                                      user.isAdmin());

  if (existSessionKey == -1) {
    throw UMSVishnuException (ERRCODE_SESSIONKEY_NOT_FOUND);
  }

  return 0;
}
Ejemplo n.º 2
0
/**
 * \brief Function to connect the session
 * \param user The object which manipulates user information
 * \param host The object which manipulates client machine information
 * \param connectOpt The options data structure for connection
 * \return raises an exception on error
 */
int
SessionServer::connectSession(UserServer user, MachineClientServer host, UMS_Data::ConnectOptions* connectOpt) {

  std::string numUserToconnect;

  msession.setAuthenId( user.getData().getUserId() );


  if (! user.isAuthenticate()) {
    throw UMSVishnuException(ERRCODE_UNKNOWN_USER);
  }

  if (! connectOpt->getSubstituteUserId().empty()) {

    user.checkUserId( connectOpt->getSubstituteUserId());

    if (! user.isAdmin()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    numUserToconnect = user.getNumUserFromId( connectOpt->getSubstituteUserId() );
    if (numUserToconnect.empty()) {
      throw UMSVishnuException(ERRCODE_UNKNOWN_USER, connectOpt->getSubstituteUserId());
    }

    msession.setUserId(connectOpt->getSubstituteUserId());
  }

  //if there is not a numSubstituteUserId
  if (numUserToconnect.empty()) {
    numUserToconnect = user.getNumUserFromLoginInfo(user.getData().getUserId(), user.getData().getPassword());
    msession.setUserId(user.getData().getUserId());
  }

  generateSessionKey(user.getData().getUserId());
  generateSessionId(user.getData().getUserId());

  //To solve the connection mode
  solveConnectionMode(connectOpt);

  host.recordMachineClient();
  recordSessionServer(host.getId(), numUserToconnect);

  return 0;
}