/** * \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 numSubstituteUserId; std::string numUserIdToconnect; //To record the connection identifier msession.setAuthenId(user.getData().getUserId()); //if the user exist if (user.isAuthenticate()) { //if a user to substitute is defined if (connectOpt->getSubstituteUserId().size() != 0) { // if the user is admin if (user.isAdmin()) { numSubstituteUserId = user.getAttribut("where " "userid='"+mdatabaseVishnu->escapeData(connectOpt->getSubstituteUserId())+"'"); //If the user to substitute exist if (! user.getNumUserId(connectOpt->getSubstituteUserId()).empty()) { numUserIdToconnect = numSubstituteUserId; msession.setUserId(connectOpt->getSubstituteUserId()); } //End If the user to substitute exist else { UMSVishnuException e(ERRCODE_UNKNOWN_USERID); throw e; } } // END if the user is admin else { UMSVishnuException e(ERRCODE_NO_ADMIN); throw e; } } //End if a user to substitute is defined //if there is not a numSubstituteUserId if (numUserIdToconnect.size() == 0) { numUserIdToconnect = user.getAttribut("where userid='"+mdatabaseVishnu->escapeData(user.getData().getUserId())+"'" " and pwd='"+mdatabaseVishnu->escapeData(user.getData().getPassword())+"'"); msession.setUserId(user.getData().getUserId()); } //END if There is not a numSubstituteUserId generateSessionKey(user.getData().getUserId()); generateSessionId(user.getData().getUserId()); //To solve the connection mode solveConnectionMode(connectOpt, numUserIdToconnect); host.recordMachineClient(); recordSessionServer(host.getId(), numUserIdToconnect); } // END if the user exist else { UMSVishnuException e(ERRCODE_UNKNOWN_USER); throw e; } return 0; }//END: connectSession(UserServer, MachineClientServer, ConnectOptions*)
/** * \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 host, std::string sessionId) { msession.setSessionId(sessionId); //If the user exists if (user.isAuthenticate()) { int state = getState(true); // -1 is an error code of getState when nohting has found if (state != -1) { //if the session is active if (state == 1) { int existSessionKey = 0; //if user is an admin if (user.isAdmin()) { existSessionKey = getSessionkey("", "", true); } //END if user is an admin else { existSessionKey = getSessionkey(host.getId(), user.getAttribut("where userid='"+mdatabaseVishnu->escapeData(user.getData().getUserId())+"'" " and pwd='"+mdatabaseVishnu->escapeData(user.getData().getPassword())+"'")); } //if there is no session key with the previous parameters if (existSessionKey == -1) { UMSVishnuException e(ERRCODE_SESSIONKEY_NOT_FOUND); throw e; } }//if the session is active else { UMSVishnuException e(ERRCODE_SESSIONKEY_EXPIRED); throw e; } }//END if state != -1 else { UMSVishnuException e(ERRCODE_UNKNOWN_SESSION_ID); throw e; } } //END IF user.exist else { UMSVishnuException e(ERRCODE_UNKNOWN_USER); throw e; } return 0; }//END: reconnect(UserServer, MachineClientServer, string sessionId)
/** * \brief Function to change the closure connection mode disconnet to timeout * \param user The object which manipulates user information * \return the new connection parameters are registered on the session data structure */ int SessionServer::disconnetToTimeout(UserServer user) { OptionValueServer optionValueServer; std::string numuserId; //To change the session close policy on CLOSE_ON_TIMEOUT on the database mdatabaseVishnu->process("UPDATE vsession SET closepolicy=1" " WHERE sessionkey='"+mdatabaseVishnu->escapeData(msession.getSessionKey())+"';"); //To change the session close policy on CLOSE_ON_TIMEOUT on the msession object msession.setClosePolicy(1); numuserId = user.getAttribut("where userid='"+mdatabaseVishnu->escapeData(user.getData().getUserId())+"'" " and pwd='"+mdatabaseVishnu->escapeData(user.getData().getPassword())+"'"); //To get the timeout msession.setTimeout(optionValueServer.getOptionValueForUser(numuserId, TIMEOUT_OPT)); mdatabaseVishnu->process("UPDATE vsession SET timeout="+convertToString(msession.getTimeout())+ " WHERE sessionkey='"+mdatabaseVishnu->escapeData(msession.getSessionKey())+"';"); return 0; }