summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-19 18:21:03 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-19 18:21:03 +0200
commit37c8bed9a5f2ae9141c461202fec5baa6fa21389 (patch)
treed29b6a74b4da709350beec3c12c91426bcd4dea8 /src/Common
parent7234fe326d16d6bf9f4374a09ddc6ef790e6723f (diff)
downloadmad-37c8bed9a5f2ae9141c461202fec5baa6fa21389.tar
mad-37c8bed9a5f2ae9141c461202fec5baa6fa21389.zip
UserManager nach Common verschoben
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Application.cpp4
-rw-r--r--src/Common/Application.h6
-rw-r--r--src/Common/CMakeLists.txt2
-rw-r--r--src/Common/UserBackend.h100
-rw-r--r--src/Common/UserManager.cpp195
-rw-r--r--src/Common/UserManager.h79
6 files changed, 385 insertions, 1 deletions
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 <matthias@gamezock.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_SERVER_USERBACKEND_H_
+#define MAD_SERVER_USERBACKEND_H_
+
+#include <config.h>
+
+#include <Core/Exception.h>
+
+#include "UserInfo.h"
+#include "GroupInfo.h"
+
+#include <map>
+#include <set>
+#include <string>
+
+#include <boost/smart_ptr.hpp>
+
+
+namespace Mad {
+namespace Common {
+
+class UserManager;
+
+class UserBackend {
+ protected:
+ friend class UserManager;
+
+ UserBackend() {}
+
+ virtual boost::shared_ptr<std::map<unsigned long, UserInfo> > getUserList() throw(Core::Exception) {
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+ }
+
+ virtual boost::shared_ptr<UserInfo> getUserInfo(unsigned long uid _UNUSED_PARAMETER_) throw(Core::Exception) {
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+ }
+
+ virtual boost::shared_ptr<UserInfo> getUserInfoByName(const std::string &name _UNUSED_PARAMETER_) throw(Core::Exception) {
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+ }
+
+ virtual boost::shared_ptr<std::set<unsigned long> > getUserGroupList(unsigned long uid _UNUSED_PARAMETER_) throw(Core::Exception) {
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+ }
+
+
+ virtual boost::shared_ptr<std::map<unsigned long, GroupInfo> > 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<std::set<unsigned long> > 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 <matthias@gamezock.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserManager.h"
+#include "UserBackend.h"
+
+namespace Mad {
+namespace Common {
+
+bool UserManager::Compare::operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2) {
+ if(b1->getPriority() == b2->getPriority())
+ return (b1.get() > b2.get());
+ else
+ return (b1->getPriority() > b2->getPriority());
+}
+
+
+boost::shared_ptr<std::map<unsigned long, UserInfo> > UserManager::getUserList() throw(Core::Exception) {
+ Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+
+ for(std::set<boost::shared_ptr<UserBackend> >::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<UserInfo> UserManager::getUserInfo(unsigned long uid) throw(Core::Exception) {
+ Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+
+ for(std::set<boost::shared_ptr<UserBackend> >::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<UserInfo> UserManager::getUserInfoByName(const std::string &name) throw(Core::Exception) {
+ Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+
+ for(std::set<boost::shared_ptr<UserBackend> >::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<std::set<unsigned long> > UserManager::getUserGroupList(unsigned long uid) throw(Core::Exception) {
+ Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+
+ for(std::set<boost::shared_ptr<UserBackend> >::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<std::map<unsigned long, GroupInfo> > UserManager::getGroupList() throw(Core::Exception) {
+ Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+
+ for(std::set<boost::shared_ptr<UserBackend> >::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<boost::shared_ptr<UserBackend> >::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<boost::shared_ptr<UserBackend> >::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<std::set<unsigned long> > UserManager::getGroupUserList(unsigned long gid) throw(Core::Exception) {
+ Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+
+ for(std::set<boost::shared_ptr<UserBackend> >::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<boost::shared_ptr<UserBackend> >::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<boost::shared_ptr<UserBackend> >::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 <matthias@gamezock.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_SERVER_USERMANAGER_H_
+#define MAD_SERVER_USERMANAGER_H_
+
+#include "UserInfo.h"
+#include "GroupInfo.h"
+
+#include <Core/Exception.h>
+
+#include <map>
+#include <set>
+
+#include <boost/smart_ptr.hpp>
+#include <boost/noncopyable.hpp>
+
+namespace Mad {
+namespace Common {
+
+class Application;
+class UserBackend;
+
+class UserManager : boost::noncopyable {
+ private:
+ friend class Application;
+
+ struct Compare {
+ bool operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2);
+ };
+
+ std::set<boost::shared_ptr<UserBackend>, Compare> backends;
+
+ UserManager() {}
+
+ public:
+ void registerBackend(boost::shared_ptr<UserBackend> backend) {
+ backends.insert(backend);
+ }
+
+ void unregisterBackend(boost::shared_ptr<UserBackend> backend) {
+ backends.erase(backend);
+ }
+
+ boost::shared_ptr<std::map<unsigned long, UserInfo> > getUserList() throw(Core::Exception);
+ boost::shared_ptr<UserInfo> getUserInfo(unsigned long uid) throw(Core::Exception);
+ boost::shared_ptr<UserInfo> getUserInfoByName(const std::string &name) throw(Core::Exception);
+ boost::shared_ptr<std::set<unsigned long> > getUserGroupList(unsigned long uid) throw(Core::Exception);
+
+ boost::shared_ptr<std::map<unsigned long, GroupInfo> > 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<std::set<unsigned long> > 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_ */