/* -------------------------------------------------------------------------- */ /* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */ /* */ /* 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. */ /* -------------------------------------------------------------------------- */ #ifndef USER_H_ #define USER_H_ #include "PoolObjectSQL.h" #include "UserTemplate.h" #include "ObjectCollection.h" #include "QuotasSQL.h" #include "LoginToken.h" #include "VMActions.h" #include "AuthRequest.h" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /** * The User class. */ class User : public PoolObjectSQL { public: virtual ~User() = default; /** * Characters that can not be in a name */ static const std::string INVALID_NAME_CHARS; /** * Characters that can not be in a password */ static const std::string INVALID_PASS_CHARS; /** * Function to print the User object into a string in XML format * @param xml the resulting XML string * @return a reference to the generated string */ std::string& to_xml(std::string& xml) const override; /** * Function to print the User object into a string in * XML format. The extended XML includes the default quotas * @param xml the resulting XML string * @return a reference to the generated string */ std::string& to_xml_extended(std::string& xml) const; /** * Check if the user is enabled * @return true if the user is enabled */ bool isEnabled() const { return enabled; } /** * Returns user password * @return the User's password */ const std::string& get_password() const { return password; }; /** * Enables the current user */ void enable() { enabled = true; }; /** * Disables the current user */ void disable() { enabled = false; session->reset(); login_tokens.reset(); }; /** * Checks if a password is valid, i.e. it is not empty and does not * contain invalid characters. * @param pass Password to be checked * @param error_str Returns the error reason, if any * @return true if the string is valid */ static bool pass_is_valid(const std::string& pass, std::string& error_str); /** * Sets user password. It checks that the new password does not contain * forbidden chars. * @param _password the new pass * @param error_str Returns the error reason, if any * @returns -1 if the password is not valid */ int set_password(const std::string& passwd, std::string& error_str); /** * Returns user password * @return the user's auth driver */ const std::string& get_auth_driver() const { return auth_driver; }; /** * Sets the user auth driver. * * @param _auth_driver the new auth. driver * @param error_str Returns the error reason, if any * @return 0 on success, -1 otherwise */ int set_auth_driver(const std::string& _auth_driver, std::string& error_str) { auth_driver = _auth_driver; session->reset(); return 0; }; /** * Splits an authentication token (:) * @param secret, the authentication token * @param username * @param password * @return 0 on success **/ static int split_secret(const std::string& secret, std::string& user, std::string& pass); /** * Factory method for image templates */ std::unique_ptr