00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PION_USERMANAGER_HEADER__
00021 #define __PION_USERMANAGER_HEADER__
00022
00023 #include <string>
00024 #include <libxml/tree.h>
00025 #include <boost/bind.hpp>
00026 #include <boost/signal.hpp>
00027 #include <pion/PionConfig.hpp>
00028 #include <pion/PionException.hpp>
00029 #include <pion/net/PionUser.hpp>
00030 #include <pion/platform/ConfigManager.hpp>
00031 #include "PlatformService.hpp"
00032
00033
00034 namespace pion {
00035 namespace server {
00036
00037
00041 class PION_SERVER_API UserManager :
00042 public pion::platform::ConfigManager,
00043 public pion::net::PionUserManager
00044 {
00045 public:
00046
00048 class MissingOpenSSLException : public std::exception {
00049 public:
00050 virtual const char* what() const throw() {
00051 return "Missing OpenSSL library: User management is disabled!";
00052 }
00053 };
00054
00056 class MissingUserIdInConfigFileException : public PionException {
00057 public:
00058 MissingUserIdInConfigFileException(const std::string& config_file)
00059 : PionException("Users configuration file includes a User without a unique identifier: ", config_file) {}
00060 };
00061
00063 class EmptyUserIdException : public PionException {
00064 public:
00065 EmptyUserIdException()
00066 : PionException("The specified User identifier is empty.") {}
00067 };
00068
00070 class NoPasswordException : public PionException {
00071 public:
00072 NoPasswordException(const std::string& user_id)
00073 : PionException("The specified User configuration has an empty or missing password. Specified User identifier: ", user_id) {}
00074 };
00075
00077 class DuplicateUserException : public PionException {
00078 public:
00079 DuplicateUserException(const std::string& user_id)
00080 : PionException("A User already exists with the specified ID: ", user_id) {}
00081 };
00082
00084 class UserNotFoundException : public PionException {
00085 public:
00086 UserNotFoundException(const std::string& user_id)
00087 : PionException("No User found for identifier: ", user_id) {}
00088 };
00089
00091 class AddUserConfigException : public PionException {
00092 public:
00093 AddUserConfigException(const std::string& config_file)
00094 : PionException("Unable to add a User to the configuration file: ", config_file) {}
00095 };
00096
00098 class UpdateUserConfigException : public PionException {
00099 public:
00100 UpdateUserConfigException(const std::string& config_file)
00101 : PionException("Unable to update a User in the configuration file: ", config_file) {}
00102 };
00103
00105 class UserUpdateFailedException : public PionException {
00106 public:
00107 UserUpdateFailedException(const std::string& user_id)
00108 : PionException("Unable to update User with identifier: ", user_id) {}
00109 };
00110
00111 public:
00112
00114 UserManager();
00115
00117 virtual ~UserManager() {}
00118
00120 virtual void openConfigFile(void);
00121
00127 virtual void writeConfigXML(std::ostream& out) const;
00128
00135 bool writeConfigXML(std::ostream& out, const std::string& user_id) const;
00136
00143 bool writePermissionsXML(std::ostream& out, const std::string& user_id) const;
00144
00154 static xmlNodePtr createUserConfig(std::string& user_id, const char *buf, std::size_t len);
00155
00165 std::string addUser(const std::string& user_id, xmlNodePtr config_ptr);
00166
00174 void setUserConfig(const std::string& user_id, xmlNodePtr config_ptr);
00175
00181 virtual bool removeUser(const std::string& user_id);
00182
00193 bool creationAllowed(
00194 const pion::net::PionUserPtr& user_from_request,
00195 const pion::platform::ConfigManager& config_manager,
00196 const xmlNodePtr& config_ptr) const;
00197
00209 bool updateAllowed(
00210 const pion::net::PionUserPtr& user_from_request,
00211 const pion::platform::ConfigManager& config_manager,
00212 const std::string& id,
00213 const xmlNodePtr& config_ptr) const;
00214
00224 bool removalAllowed(
00225 const pion::net::PionUserPtr& user_from_request,
00226 const pion::platform::ConfigManager& config_manager,
00227 const std::string& id) const;
00228
00238 bool accessAllowed(
00239 const pion::net::PionUserPtr& user_from_request,
00240 const pion::platform::ConfigManager& config_manager,
00241 const std::string& plugin_id) const;
00242
00252 bool accessAllowed(
00253 const pion::net::PionUserPtr& user_from_request,
00254 const PlatformService& service,
00255 const std::string& id = "") const;
00256
00257
00258 private:
00259
00273 bool updateUserManager(const std::string& user_id, xmlNodePtr config_ptr,
00274 bool password_encrypted, bool new_user);
00275
00284 bool setUserConfig(xmlNodePtr user_node_ptr, xmlNodePtr config_ptr);
00285
00293 bool isAdmin(const pion::net::PionUserPtr user_ptr) const;
00294
00303 xmlNodePtr getPermissionNode(pion::net::PionUserPtr user_ptr, const std::string& permission_type) const;
00304
00305
00306 private:
00307
00309 static const std::string DEFAULT_CONFIG_FILE;
00310
00312 static const std::string USER_ELEMENT_NAME;
00313
00315 static const std::string PASSWORD_ELEMENT_NAME;
00316
00318 static const std::string USER_PERMISSION_ELEMENT_NAME;
00319
00321 static const std::string PERMISSION_TYPE_ATTRIBUTE_NAME;
00322
00324 static const std::string ADMIN_PERMISSION_TYPE;
00325
00327 mutable boost::mutex m_mutex;
00328 };
00329
00331 typedef boost::shared_ptr<UserManager> UserManagerPtr;
00332
00333
00334 }
00335 }
00336
00337 #endif //__PION_USERMANAGER_HEADER__