summaryrefslogtreecommitdiffstats
path: root/src/Common/UserManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/UserManager.cpp')
-rw-r--r--src/Common/UserManager.cpp351
1 files changed, 99 insertions, 252 deletions
diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp
index 928289b..d528137 100644
--- a/src/Common/UserManager.cpp
+++ b/src/Common/UserManager.cpp
@@ -20,344 +20,191 @@
#include "UserManager.h"
#include "UserCache.h"
-#include <iostream>
-
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());
+void UserManager::registerBackend(boost::shared_ptr<UserDBBackend> backend) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+
+ const std::string &name = backend->getName();
+
+ dbBackends.insert(std::make_pair(backend, std::make_pair(backend, name)));
+ dbBackendNames.insert(std::make_pair(name, backend));
+
+ if(!dbBackend)
+ dbBackend = backend;
}
+void UserManager::registerBackendCached(boost::shared_ptr<UserDBBackend> backend) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+
+ const std::string &name = backend->getName();
+
+ boost::shared_ptr<UserCache> cache(new UserCache(application, backend));
-void UserManager::registerBackendCached(boost::shared_ptr<UserBackend> backend) {
- {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
- backends.insert(std::make_pair(backend, boost::shared_ptr<UserCache>(new UserCache(application, backend))));
- }
+ dbBackends.insert(std::make_pair(backend, std::make_pair(cache, name)));
+ dbBackendNames.insert(std::make_pair(name, backend));
+
+ if(!dbBackend)
+ dbBackend = cache;
}
boost::shared_ptr<const std::map<unsigned long, UserInfo> > UserManager::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getUserList(timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getUserList(timestamp);
}
boost::shared_ptr<const UserInfo> UserManager::getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getUserInfo(uid, timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getUserInfo(uid, timestamp);
}
boost::shared_ptr<const UserInfo> UserManager::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getUserInfoByName(name, timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getUserInfoByName(name, timestamp);
}
boost::shared_ptr<const std::set<unsigned long> > UserManager::getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getUserGroupList(uid, timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getUserGroupList(uid, timestamp);
}
boost::shared_ptr<const std::map<unsigned long, GroupInfo> > UserManager::getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
-
- boost::shared_ptr<const std::map<unsigned long, GroupInfo> > ret;
-
- {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getGroupList(timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
- }
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- throw e;
+ return dbBackend->getGroupList(timestamp);
}
boost::shared_ptr<const GroupInfo> UserManager::getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getGroupInfo(gid, timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getGroupInfo(gid, timestamp);
}
boost::shared_ptr<const GroupInfo> UserManager::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getGroupInfoByName(name, timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getGroupInfoByName(name, timestamp);
}
boost::shared_ptr<const std::set<unsigned long> > UserManager::getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getGroupUserList(gid, timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getGroupUserList(gid, timestamp);
}
boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > UserManager::getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- return backend->second->getFullUserGroupList(timestamp);
- }
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
- }
- }
-
- throw e;
+ return dbBackend->getFullUserGroupList(timestamp);
}
-void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
-
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->setPassword(uid, password);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+void UserManager::setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) throw(Core::Exception) {
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
}
void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->addUser(userInfo);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ dbBackend->addUser(userInfo);
}
void UserManager::updateUser(unsigned long uid, const UserInfo &userInfo) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->updateUser(uid, userInfo);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ dbBackend->updateUser(uid, userInfo);
}
void UserManager::deleteUser(unsigned long uid) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->deleteUser(uid);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ dbBackend->deleteUser(uid);
}
void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->addGroup(groupInfo);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ dbBackend->addGroup(groupInfo);
}
void UserManager::updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->updateGroup(gid, groupInfo);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ dbBackend->updateGroup(gid, groupInfo);
}
void UserManager::deleteGroup(unsigned long gid) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->deleteGroup(gid);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ dbBackend->deleteGroup(gid);
}
void UserManager::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->addUserToGroup(uid, gid);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ dbBackend->addUserToGroup(uid, gid);
}
void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
- boost::lock_guard<boost::shared_mutex> lock(mutex);
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- try {
- backend->second->deleteUserFromGroup(uid, gid);
- return;
- }
- catch(Core::Exception e) {
- if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- throw e;
- }
- }
-
- throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+ dbBackend->deleteUserFromGroup(uid, gid);
}
}