//////////////////////////////////////////////////////////////////////////////// /// @brief session management /// /// @file /// /// DISCLAIMER /// /// Copyright 2004-2012 triagens GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Dr. Frank Celler /// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef TRIAGENS_USER_MANAGER_SESSION_H #define TRIAGENS_USER_MANAGER_SESSION_H 1 #include "Basics/Common.h" #include "UserManager/Right.h" #include "Basics/Mutex.h" namespace triagens { namespace admin { class User; // ----------------------------------------------------------------------------- // --SECTION-- class Session // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief session management //////////////////////////////////////////////////////////////////////////////// class Session { //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- static constants // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief maximal number of open sessions //////////////////////////////////////////////////////////////////////////////// static size_t const MAXIMAL_OPEN_SESSION = 10; //////////////////////////////////////////////////////////////////////////////// /// @brief length of session identifier //////////////////////////////////////////////////////////////////////////////// static size_t const SID_LENGTH = 10; //////////////////////////////////////////////////////////////////////////////// /// @brief length of session characters //////////////////////////////////////////////////////////////////////////////// static string const SID_CHARACTERS; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- static variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief access lock //////////////////////////////////////////////////////////////////////////////// static basics::Mutex lock; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- static public methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns a role by name //////////////////////////////////////////////////////////////////////////////// static Session* lookup (string const& sid); //////////////////////////////////////////////////////////////////////////////// /// @brief creates a session //////////////////////////////////////////////////////////////////////////////// static Session* create (); //////////////////////////////////////////////////////////////////////////////// /// @brief removes a session /// /// Remove will also delete the session object. //////////////////////////////////////////////////////////////////////////////// static bool remove (Session*); //////////////////////////////////////////////////////////////////////////////// /// @brief sets a anonymous rights //////////////////////////////////////////////////////////////////////////////// static void setAnonymousRights (vector const&); //////////////////////////////////////////////////////////////////////////////// /// @brief gets anonymous rights //////////////////////////////////////////////////////////////////////////////// static set const& anonymousRights (); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// protected: //////////////////////////////////////////////////////////////////////////////// /// @brief creates a new sessions //////////////////////////////////////////////////////////////////////////////// Session (string const& sid); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns the session identifier //////////////////////////////////////////////////////////////////////////////// string const& getSid () const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns the user of a session //////////////////////////////////////////////////////////////////////////////// User* getUser () const; //////////////////////////////////////////////////////////////////////////////// /// @brief logs a user in //////////////////////////////////////////////////////////////////////////////// bool login (string const& username, string const& password, string& reason); //////////////////////////////////////////////////////////////////////////////// /// @brief logs a user out //////////////////////////////////////////////////////////////////////////////// bool logout (); //////////////////////////////////////////////////////////////////////////////// /// @brief checks for a right //////////////////////////////////////////////////////////////////////////////// bool hasRight (right_t); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- static private variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief rights //////////////////////////////////////////////////////////////////////////////// static set _rights; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup RestServer /// @{ //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief session identifier //////////////////////////////////////////////////////////////////////////////// string const _sid; //////////////////////////////////////////////////////////////////////////////// /// @brief user //////////////////////////////////////////////////////////////////////////////// User* _user; }; } } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" // End: