From 37c8bed9a5f2ae9141c461202fec5baa6fa21389 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 19 Jun 2009 18:21:03 +0200 Subject: UserManager nach Common verschoben --- src/Common/Application.cpp | 4 +- src/Common/Application.h | 6 + src/Common/CMakeLists.txt | 2 + src/Common/UserBackend.h | 100 +++++++++++ src/Common/UserManager.cpp | 195 +++++++++++++++++++++ src/Common/UserManager.h | 79 +++++++++ src/Server/Application.cpp | 7 +- src/Server/Application.h | 6 - src/Server/CMakeLists.txt | 2 - .../RequestHandlers/UserRequestHandlerGroup.cpp | 2 +- src/Server/UserBackend.h | 100 ----------- src/Server/UserManager.cpp | 195 --------------------- src/Server/UserManager.h | 79 --------- src/modules/UserBackendMysql/Module.h | 13 +- src/modules/UserBackendMysql/UserBackendMysql.h | 5 +- 15 files changed, 392 insertions(+), 403 deletions(-) create mode 100644 src/Common/UserBackend.h create mode 100644 src/Common/UserManager.cpp create mode 100644 src/Common/UserManager.h delete mode 100644 src/Server/UserBackend.h delete mode 100644 src/Server/UserManager.cpp delete mode 100644 src/Server/UserManager.h diff --git a/src/Common/Application.cpp b/src/Common/Application.cpp index 950e61b..6eca8d3 100644 --- a/src/Common/Application.cpp +++ b/src/Common/Application.cpp @@ -21,14 +21,16 @@ #include "ModuleManager.h" #include "RequestManager.h" #include "SystemManager.h" +#include "UserManager.h" namespace Mad { namespace Common { Application::Application(bool server) : moduleManager(new ModuleManager(this)), requestManager(new RequestManager(this, server)), -systemManager(new SystemManager) {} +systemManager(new SystemManager), userManager(new UserManager) {} Application::~Application() { + delete userManager; delete systemManager; delete requestManager; delete moduleManager; diff --git a/src/Common/Application.h b/src/Common/Application.h index 332e4c7..9da1f03 100644 --- a/src/Common/Application.h +++ b/src/Common/Application.h @@ -28,12 +28,14 @@ namespace Common { class ModuleManager; class RequestManager; class SystemManager; +class UserManager; class Application : public Core::Application { private: ModuleManager *moduleManager; RequestManager *requestManager; SystemManager *systemManager; + UserManager *userManager; protected: Application(bool server); @@ -51,6 +53,10 @@ class Application : public Core::Application { SystemManager* getSystemManager() const { return systemManager; } + + UserManager* getUserManager() const { + return userManager; + } }; } diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 4a4eb8e..3ec77c4 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -20,7 +20,9 @@ add_library(Common RequestManager.cpp RequestManager.h SystemBackend.h SystemManager.cpp SystemManager.h + UserBackend.h UserInfo.h + UserManager.cpp UserManager.h XmlPacket.cpp XmlPacket.h ) target_link_libraries(Common RequestHandlers Requests Net ${LIBXML2_LIBRARIES} ${LTDL_LIBRARIES}) diff --git a/src/Common/UserBackend.h b/src/Common/UserBackend.h new file mode 100644 index 0000000..16db16c --- /dev/null +++ b/src/Common/UserBackend.h @@ -0,0 +1,100 @@ +/* + * UserBackend.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef MAD_SERVER_USERBACKEND_H_ +#define MAD_SERVER_USERBACKEND_H_ + +#include + +#include + +#include "UserInfo.h" +#include "GroupInfo.h" + +#include +#include +#include + +#include + + +namespace Mad { +namespace Common { + +class UserManager; + +class UserBackend { + protected: + friend class UserManager; + + UserBackend() {} + + virtual boost::shared_ptr > getUserList() throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual boost::shared_ptr getUserInfo(unsigned long uid _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual boost::shared_ptr getUserInfoByName(const std::string &name _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual boost::shared_ptr > getUserGroupList(unsigned long uid _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + + virtual boost::shared_ptr > getGroupList() throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual std::string getGroupName(unsigned long gid _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual unsigned long getGroupId(const std::string &name _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual boost::shared_ptr > getGroupUserList(unsigned long gid _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual void setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual void addUser(const UserInfo &userInfo _UNUSED_PARAMETER_) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + + virtual int getPriority() const { + return 0; + } + + public: + virtual ~UserBackend() {} +}; + +} +} + +#endif /* MAD_SERVER_USERBACKEND_H_ */ diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp new file mode 100644 index 0000000..6f5f548 --- /dev/null +++ b/src/Common/UserManager.cpp @@ -0,0 +1,195 @@ +/* + * UserManager.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "UserManager.h" +#include "UserBackend.h" + +namespace Mad { +namespace Common { + +bool UserManager::Compare::operator() (boost::shared_ptr b1, boost::shared_ptr b2) { + if(b1->getPriority() == b2->getPriority()) + return (b1.get() > b2.get()); + else + return (b1->getPriority() > b2->getPriority()); +} + + +boost::shared_ptr > UserManager::getUserList() throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getUserList(); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +boost::shared_ptr UserManager::getUserInfo(unsigned long uid) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getUserInfo(uid); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +boost::shared_ptr UserManager::getUserInfoByName(const std::string &name) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getUserInfoByName(name); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +boost::shared_ptr > UserManager::getUserGroupList(unsigned long uid) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getUserGroupList(uid); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +boost::shared_ptr > UserManager::getGroupList() throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getGroupList(); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +std::string UserManager::getGroupName(unsigned long gid) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getGroupName(gid); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +unsigned long UserManager::getGroupId(const std::string &name) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getGroupId(name); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +boost::shared_ptr > UserManager::getGroupUserList(unsigned long gid) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->getGroupUserList(gid); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->setPassword(uid, password); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); + + for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + try { + return (*backend)->addUser(userInfo); + } + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + e = e2; + } + } + + throw e; +} + +} +} diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h new file mode 100644 index 0000000..bdf39c1 --- /dev/null +++ b/src/Common/UserManager.h @@ -0,0 +1,79 @@ +/* + * UserManager.h + * + * Copyright (C) 2009 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef MAD_SERVER_USERMANAGER_H_ +#define MAD_SERVER_USERMANAGER_H_ + +#include "UserInfo.h" +#include "GroupInfo.h" + +#include + +#include +#include + +#include +#include + +namespace Mad { +namespace Common { + +class Application; +class UserBackend; + +class UserManager : boost::noncopyable { + private: + friend class Application; + + struct Compare { + bool operator() (boost::shared_ptr b1, boost::shared_ptr b2); + }; + + std::set, Compare> backends; + + UserManager() {} + + public: + void registerBackend(boost::shared_ptr backend) { + backends.insert(backend); + } + + void unregisterBackend(boost::shared_ptr backend) { + backends.erase(backend); + } + + boost::shared_ptr > getUserList() throw(Core::Exception); + boost::shared_ptr getUserInfo(unsigned long uid) throw(Core::Exception); + boost::shared_ptr getUserInfoByName(const std::string &name) throw(Core::Exception); + boost::shared_ptr > getUserGroupList(unsigned long uid) throw(Core::Exception); + + boost::shared_ptr > getGroupList() throw(Core::Exception); + std::string getGroupName(unsigned long gid) throw(Core::Exception); + unsigned long getGroupId(const std::string &name) throw(Core::Exception); + boost::shared_ptr > getGroupUserList(unsigned long gid) throw(Core::Exception); + + void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); + + void addUser(const UserInfo &userInfo) throw(Core::Exception); +}; + +} +} + +#endif /* MAD_SERVER_USERMANAGER_H_ */ diff --git a/src/Server/Application.cpp b/src/Server/Application.cpp index 3414e53..dc9fa5f 100644 --- a/src/Server/Application.cpp +++ b/src/Server/Application.cpp @@ -19,18 +19,13 @@ #include "Application.h" #include "ConnectionManager.h" -#include "UserManager.h" namespace Mad { namespace Server { -Application::Application() : Common::Application(true), connectionManager(new ConnectionManager(this)), -userManager(new UserManager) { - -} +Application::Application() : Common::Application(true), connectionManager(new ConnectionManager(this)) {} Application::~Application() { - delete userManager; delete connectionManager; } diff --git a/src/Server/Application.h b/src/Server/Application.h index b62893b..600458f 100644 --- a/src/Server/Application.h +++ b/src/Server/Application.h @@ -26,12 +26,10 @@ namespace Mad { namespace Server { class ConnectionManager; -class UserManager; class Application : public Common::Application { private: ConnectionManager *connectionManager; - UserManager *userManager; public: Application(); @@ -40,10 +38,6 @@ class Application : public Common::Application { ConnectionManager* getConnectionManager() const { return connectionManager; } - - UserManager* getUserManager() const { - return userManager; - } }; } diff --git a/src/Server/CMakeLists.txt b/src/Server/CMakeLists.txt index b609de3..22a7826 100644 --- a/src/Server/CMakeLists.txt +++ b/src/Server/CMakeLists.txt @@ -6,7 +6,5 @@ include_directories(${INCLUDES}) add_library(Server Application.cpp Application.h ConnectionManager.cpp ConnectionManager.h - UserBackend.h - UserManager.cpp UserManager.h ) target_link_libraries(Server ServerRequestHandlers ServerRequests Common) diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp index 3aaa576..34fae36 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp @@ -19,7 +19,7 @@ #include "UserRequestHandlerGroup.h" #include "../Application.h" -#include "../UserManager.h" +#include namespace Mad { namespace Server { diff --git a/src/Server/UserBackend.h b/src/Server/UserBackend.h deleted file mode 100644 index 4688bc7..0000000 --- a/src/Server/UserBackend.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * UserBackend.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef MAD_SERVER_USERBACKEND_H_ -#define MAD_SERVER_USERBACKEND_H_ - -#include - -#include - -#include -#include - -#include -#include -#include - -#include - - -namespace Mad { -namespace Server { - -class UserManager; - -class UserBackend { - protected: - friend class UserManager; - - UserBackend() {} - - virtual boost::shared_ptr > getUserList() throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual boost::shared_ptr getUserInfo(unsigned long uid _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual boost::shared_ptr getUserInfoByName(const std::string &name _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual boost::shared_ptr > getUserGroupList(unsigned long uid _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - - virtual boost::shared_ptr > getGroupList() throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual std::string getGroupName(unsigned long gid _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual unsigned long getGroupId(const std::string &name _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual boost::shared_ptr > getGroupUserList(unsigned long gid _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual void setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual void addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual int getPriority() const { - return 0; - } - - public: - virtual ~UserBackend() {} -}; - -} -} - -#endif /* MAD_SERVER_USERBACKEND_H_ */ diff --git a/src/Server/UserManager.cpp b/src/Server/UserManager.cpp deleted file mode 100644 index 243457c..0000000 --- a/src/Server/UserManager.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * UserManager.cpp - * - * Copyright (C) 2009 Matthias Schiffer - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include "UserManager.h" -#include "UserBackend.h" - -namespace Mad { -namespace Server { - -bool UserManager::Compare::operator() (boost::shared_ptr b1, boost::shared_ptr b2) { - if(b1->getPriority() == b2->getPriority()) - return (b1.get() > b2.get()); - else - return (b1->getPriority() > b2->getPriority()); -} - - -boost::shared_ptr > UserManager::getUserList() throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getUserList(); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -boost::shared_ptr UserManager::getUserInfo(unsigned long uid) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getUserInfo(uid); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -boost::shared_ptr UserManager::getUserInfoByName(const std::string &name) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getUserInfoByName(name); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -boost::shared_ptr > UserManager::getUserGroupList(unsigned long uid) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getUserGroupList(uid); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -boost::shared_ptr > UserManager::getGroupList() throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getGroupList(); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -std::string UserManager::getGroupName(unsigned long gid) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getGroupName(gid); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -unsigned long UserManager::getGroupId(const std::string &name) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getGroupId(name); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -boost::shared_ptr > UserManager::getGroupUserList(unsigned long gid) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->getGroupUserList(gid); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->setPassword(uid, password); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -void UserManager::addUser(const Common::UserInfo &userInfo) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - - for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - try { - return (*backend)->addUser(userInfo); - } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; - } - } - - throw e; -} - -} -} diff --git a/src/Server/UserManager.h b/src/Server/UserManager.h deleted file mode 100644 index 6d3c034..0000000 --- a/src/Server/UserManager.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * UserManager.h - * - * Copyright (C) 2009 Matthias Schiffer - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef MAD_SERVER_USERMANAGER_H_ -#define MAD_SERVER_USERMANAGER_H_ - -#include -#include - -#include - -#include -#include - -#include -#include - -namespace Mad { -namespace Server { - -class Application; -class UserBackend; - -class UserManager : boost::noncopyable { - private: - friend class Application; - - struct Compare { - bool operator() (boost::shared_ptr b1, boost::shared_ptr b2); - }; - - std::set, Compare> backends; - - UserManager() {} - - public: - void registerBackend(boost::shared_ptr backend) { - backends.insert(backend); - } - - void unregisterBackend(boost::shared_ptr backend) { - backends.erase(backend); - } - - boost::shared_ptr > getUserList() throw(Core::Exception); - boost::shared_ptr getUserInfo(unsigned long uid) throw(Core::Exception); - boost::shared_ptr getUserInfoByName(const std::string &name) throw(Core::Exception); - boost::shared_ptr > getUserGroupList(unsigned long uid) throw(Core::Exception); - - boost::shared_ptr > getGroupList() throw(Core::Exception); - std::string getGroupName(unsigned long gid) throw(Core::Exception); - unsigned long getGroupId(const std::string &name) throw(Core::Exception); - boost::shared_ptr > getGroupUserList(unsigned long gid) throw(Core::Exception); - - void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); - - void addUser(const Common::UserInfo &userInfo) throw(Core::Exception); -}; - -} -} - -#endif /* MAD_SERVER_USERMANAGER_H_ */ diff --git a/src/modules/UserBackendMysql/Module.h b/src/modules/UserBackendMysql/Module.h index 31f6692..96be5a7 100644 --- a/src/modules/UserBackendMysql/Module.h +++ b/src/modules/UserBackendMysql/Module.h @@ -22,8 +22,7 @@ #include "UserBackendMysql.h" -#include -#include +#include #include namespace Mad { @@ -38,17 +37,11 @@ class Module : public Common::Module { public: Module(Common::Application *application0) : application(application0), backend(new UserBackendMysql(application)) { - Server::Application *app = dynamic_cast(application); - - if(app) - app->getUserManager()->registerBackend(backend); + application->getUserManager()->registerBackend(backend); } virtual ~Module() { - Server::Application *app = dynamic_cast(application); - - if(app) - app->getUserManager()->unregisterBackend(backend); + application->getUserManager()->unregisterBackend(backend); } }; diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h index aa141da..77f0700 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.h +++ b/src/modules/UserBackendMysql/UserBackendMysql.h @@ -20,8 +20,7 @@ #ifndef MAD_MODULES_USERBACKENDMYSQL_USERBACKENDMYSQL_H_ #define MAD_MODULES_USERBACKENDMYSQL_USERBACKENDMYSQL_H_ -#include - +#include #include #include @@ -33,7 +32,7 @@ namespace Mad { namespace Modules { namespace UserBackendMysql { -class UserBackendMysql : public Server::UserBackend, private Core::Configurable { +class UserBackendMysql : public Common::UserBackend, private Core::Configurable { private: Common::Application *application; -- cgit v1.2.3