/** * \brief Constructor * \fn UserServer(std::string userId, std::string password) * \param userId The userId of the user * \param password The password of the user */ UserServer::UserServer(std::string userId, std::string password) { DbFactory factory; muser.setUserId(userId); muser.setPassword(password); mdatabaseVishnu = factory.getDatabaseInstance(); msessionServer = NULL; }
/** * \brief Constructor * \param session The session data structure * \param timeout Lenght of the connection before timeout */ SessionServer::SessionServer(const UMS_Data::Session& session, int timeout) : msession(session), mtimeout(timeout) { DbFactory factory; mdatabase = factory.getDatabaseInstance(); }
/** * \brief Constructor * \param sessionKey The session key of the session * \param timeout Lenght of the connection before timeout */ SessionServer::SessionServer(std::string sessionKey, int timeout) : mtimeout(timeout) { DbFactory factory; msession.setSessionKey(sessionKey); mdatabase = factory.getDatabaseInstance(); }
/** * \brief Constructor */ SessionServer::SessionServer() : mtimeout(DEFAULT_CONNECTION_TIMEOUT) { DbFactory factory; msession.setSessionKey(""); mdatabase = factory.getDatabaseInstance(); }
bool UMSAuthenticator::authenticate(UMS_Data::User& user) { DbFactory factory; Database* databaseVishnu = factory.getDatabaseInstance(); //To encrypt the clear password user.setPassword(vishnu::cryptPassword(user.getUserId(), user.getPassword())); std::string sqlCommand = (boost::format("SELECT numuserid" " FROM users" " WHERE userid='%1%'" " AND pwd='%2%'" " AND users.status<>%3%" )%databaseVishnu->escapeData(user.getUserId()) %databaseVishnu->escapeData(user.getPassword()) %vishnu::STATUS_DELETED).str(); boost::scoped_ptr<DatabaseResult> result(databaseVishnu->getResult(sqlCommand.c_str())); return (result->getFirstElement().size() != 0); }
int registerSeD(const std::string& sedUri, const std::string& dispUri, const std::string& sedType, const ExecConfiguration& config, std::vector<std::string>& services) { std::string mid; std::string uriSupervisor; // Getting the machine id if (sedType == "umssed") { // if ums config.getConfigValue<std::string>(vishnu::MACHINEID, mid); } else { config.getRequiredConfigValue<std::string>(vishnu::MACHINEID, mid); } int timeout = vishnu::DEFAUT_TIMEOUT; config.getConfigValue<int>(vishnu::TIMEOUT, timeout); if (config.getConfigValue<std::string>(vishnu::URISUPERVISOR, uriSupervisor) && vishnu::isNew(uriSupervisor, mid, sedType)) { try { DbFactory factory; Database* database = factory.getDatabaseInstance(); std::string request = (boost::format("INSERT INTO process (dietname, launchscript," " machineid, pstatus, uptime, vishnuname)" " VALUES ('%1%','%2%','%3%',%4%,CURRENT_TIMESTAMP, '%5%')") %uriSupervisor %database->escapeData(config.scriptToString()) %mid %vishnu::convertToString(vishnu::PRUNNING) %sedType ).str(); database->process(request.c_str()); } catch (...) { if (sedType == "umssed") { throw; } } } return 0; }
/** * \brief To initialize the FMS monitor with individual parameters instead of configuration file * \param vishnuId The password of the root user vishnu_user for the connection with the database * \param dbConfig The configuration of the database * \param machineId The machine identifier * \param batchType The batch scheduler type * \return raises an execption */ void MonitorFMS::init(int vishnuId, DbConfiguration dbConfig) { DbFactory factory; mdatabaseVishnu = factory.createDatabaseInstance(dbConfig); std::string sqlCommand("SELECT * FROM vishnu where vishnuid="+vishnu::convertToString(vishnuId)); try { /*connection to the database*/ mdatabaseVishnu->connect(); /* Checking of vishnuid on the database */ boost::scoped_ptr<DatabaseResult> result(mdatabaseVishnu->getResult(sqlCommand.c_str())); if (result->getResults().size() == 0) { throw SystemException(ERRCODE_DBERR, "The vishnuid is unrecognized"); } } catch (VishnuException& e) { exit(0); } }
int ServerXMS::init(SedConfig& cfg) { using vishnu::convertToString; using vishnu::UMSMAPPERNAME; using vishnu::FMSMAPPERNAME; using vishnu::TMSMAPPERNAME; msendmailScriptPath = cfg.sendmailScriptPath; DbFactory factory; AuthenticatorFactory authfactory; int errorCode(0); setenv("VISHNU_DEBUG_LEVEL", vishnu::convertToString(mdebugLevel).c_str(), 0); //set the machineId mmachineId = cfg.mid; // initialize the SeD configuration object msedConfig = &cfg.config; mhasUMS = cfg.hasUMS; mhasTMS = cfg.hasTMS; mhasFMS = cfg.hasFMS; // set the debug level bool isSetDebugLevel = msedConfig->getConfigValue(vishnu::DEBUG_LEVEL, mdebugLevel); if (!isSetDebugLevel || mdebugLevel < 0) { mdebugLevel = 0; } //initialization of the batchType mbatchType = cfg.batchType; if (mhasTMS) { //initialization of the batchVersion if (mbatchType != DELTACLOUD && mbatchType != OPENNEBULA) { msedConfig->getRequiredConfigValue<std::string>(vishnu::BATCHVERSION, mbatchVersion); } std::string batchDefaultConfigFile; if (msedConfig->getConfigValue(vishnu::DEFAULTBATCHCONFIGFILE, batchDefaultConfigFile)) { switch(mbatchType) { case TORQUE: getConfigOptions(batchDefaultConfigFile.c_str(), mdefaultBatchOption, "#PBS"); break; case LOADLEVELER: getConfigOptions(batchDefaultConfigFile.c_str(), mdefaultBatchOption, "# @"); break; case SLURM: getConfigOptions(batchDefaultConfigFile.c_str(), mdefaultBatchOption, "#SBATCH"); break; case LSF: getConfigOptions(batchDefaultConfigFile.c_str(), mdefaultBatchOption, "#BSUB"); break; case SGE: getConfigOptions(batchDefaultConfigFile.c_str(), mdefaultBatchOption, "#$"); break; case PBSPRO: getConfigOptions(batchDefaultConfigFile.c_str(), mdefaultBatchOption, "#PBS"); break; case DELTACLOUD: //No yet supported break; case POSIX: //No yet supported break; default: break; } } } try { mdatabaseVishnu = factory.createDatabaseInstance(cfg.dbConfig); mauthenticator = authfactory.createAuthenticatorInstance(cfg.authenticatorConfig); mvishnuId = cfg.vishnuId; std::string sqlCommand("SELECT * FROM vishnu where vishnuid="+convertToString(mvishnuId)); /*connection to the database*/ mdatabaseVishnu->connect(); mmapperTMS = new TMSMapper(MapperRegistry::getInstance(), TMSMAPPERNAME); mmapperTMS->registerMapper(); mmapperFMS = new FMSMapper(MapperRegistry::getInstance(), FMSMAPPERNAME); mmapperFMS->registerMapper(); mmapperUMS = new UMSMapper(MapperRegistry::getInstance(), UMSMAPPERNAME); mmapperUMS->registerMapper(); /* Checking of vishnuid on the database */ boost::scoped_ptr<DatabaseResult> result(mdatabaseVishnu->getResult(sqlCommand.c_str())); if (result->getResults().size() == 0) { SystemException e(ERRCODE_DBERR, "The vishnuid is unrecognized"); throw e; } } catch (VishnuException& e) { std::cout << e.what() << "\n"; errorCode = 1; } // initialization of the service table initMap(cfg.mid); return errorCode; }
SysInfoServer::SysInfoServer(const UserServer session):msession(session) { DbFactory factory; mdatabase = factory.getDatabaseInstance(); mvishnuId = 1; }
/** * \brief Constructor * \fn UserServer(SessionServer sessionServer) * \param sessionServer The object to manipulate session */ UserServer::UserServer(SessionServer sessionServer): msessionServer(&sessionServer) { DbFactory factory; mdatabaseVishnu = factory.getDatabaseInstance(); }
/** * \brief Constructor * \fn UserServer(const UMS_Data::User& user) * \param user The user data structure */ UserServer::UserServer(const UMS_Data::User& user):muser(user) { DbFactory factory; mdatabaseVishnu = factory.getDatabaseInstance(); msessionServer = NULL; }
/** * \brief Constructor */ SessionServer::SessionServer() { DbFactory factory; msession.setSessionKey(""); mdatabaseVishnu = factory.getDatabaseInstance(); }
bool LDAPAuthenticator::authenticate(UMS_Data::User& user) { bool authenticated = false; std::string uri, authlogin, authpassword, ldapbase, authSystemStatus, userid, pwd; DbFactory factory; Database* databaseVishnu = factory.getDatabaseInstance(); std::string sqlCommand = (boost::format("SELECT uri, authlogin, authpassword, ldapbase, authsystem.status, userid, pwd" " FROM ldapauthsystem, authsystem, authaccount, users" " WHERE aclogin='******'" " AND authsystem.authtype=%2%" " AND authaccount.authsystem_authsystemid=authsystem.numauthsystemid" " AND ldapauthsystem.authsystem_authsystemid=authsystem.numauthsystemid" " AND authaccount.users_numuserid=users.numuserid" " AND authsystem.status<>%3%" " AND users.status<>%4%" )%databaseVishnu->escapeData(user.getUserId()) %LDAPTYPE %vishnu::STATUS_DELETED %vishnu::STATUS_DELETED).str(); boost::scoped_ptr<DatabaseResult> result(databaseVishnu->getResult(sqlCommand.c_str())); //If there is no results if (result->getNbTuples() == 0) { UMSVishnuException e (ERRCODE_UNKNOWN_USER, "There is no user-authentication account declared in VISHNU with this identifier"); throw e; } std::vector<std::string> tmp; std::vector<std::string>::iterator ii; for (int i = 0; i < static_cast <int> (result->getNbTuples()); ++i) { tmp.clear(); tmp = result->get(i); ii=tmp.begin(); uri = *ii; authlogin = *(++ii); authpassword = *(++ii); ldapbase = *(++ii); authSystemStatus = *(++ii); userid = *(++ii); pwd = *(++ii); if (vishnu::convertToInt(authSystemStatus) != vishnu::STATUS_ACTIVE) { UMSVishnuException e (ERRCODE_UNKNOWN_AUTH_SYSTEM, "It is locked"); throw e; } try { LDAPProxy ldapPoxy(uri, user.getUserId(), "", user.getPassword()); ldapPoxy.connectLDAP(ldapbase); authenticated = true; user.setUserId(userid); user.setPassword(pwd); break; } catch (UMSVishnuException& e) { if (e.getMsgI() != ERRCODE_UNKNOWN_USER) { throw UMSVishnuException(e); } } catch (SystemException& e) { //If there is a connection problem to LDAP and it is not the last LDAP account to check if ((e.getMsgI() == ERRCODE_AUTHENTERR) && (i == (static_cast <int> (result->getNbTuples())-1))) { throw SystemException(e); } } } return authenticated; }
/** * \brief Constructor * \param machine The machine data structure * \param session The object which encapsulates session data */ MachineServer::MachineServer(UMS_Data::Machine*& machine, SessionServer& session): mmachine(machine), msessionServer(session) { DbFactory factory; mdatabase = factory.getDatabaseInstance(); }
/** * \brief Constructor * \param machine The machine data structure */ MachineServer::MachineServer(UMS_Data::Machine*& machine): mmachine(machine) { DbFactory factory; mdatabase = factory.getDatabaseInstance(); }
/** * \brief Constructor * \param session The session data structure */ SessionServer::SessionServer(const UMS_Data::Session& session):msession(session) { DbFactory factory; mdatabaseVishnu = factory.getDatabaseInstance(); }
/** * \brief Constructor * \param sessionKey The session key of the session */ SessionServer::SessionServer(std::string sessionKey) { DbFactory factory; msession.setSessionKey(sessionKey); mdatabaseVishnu = factory.getDatabaseInstance(); }