diff options
-rw-r--r-- | src/Common/UserManager.cpp | 120 |
1 files changed, 112 insertions, 8 deletions
diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index d528137..ebeb26d 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -18,7 +18,9 @@ */ #include "UserManager.h" +#include "Application.h" #include "UserCache.h" +#include "UserConfigBackend.h" namespace Mad { namespace Common { @@ -136,75 +138,177 @@ void UserManager::setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::s } void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) { - 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); dbBackend->addUser(userInfo); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->addUser(userInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::updateUser(unsigned long uid, const UserInfo &userInfo) throw(Core::Exception) { - 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); + boost::shared_ptr<const UserInfo> oldUserInfo = dbBackend->getUserInfo(uid, 0); + if(!oldUserInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->updateUser(uid, userInfo); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->updateUser(*oldUserInfo, userInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::deleteUser(unsigned long uid) throw(Core::Exception) { - 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); + boost::shared_ptr<const UserInfo> userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->deleteUser(uid); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->deleteUser(*userInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) { - 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); dbBackend->addGroup(groupInfo); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->addGroup(groupInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception) { - 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); + boost::shared_ptr<const GroupInfo> oldGroupInfo = dbBackend->getGroupInfo(gid, 0); + if(!oldGroupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->updateGroup(gid, groupInfo); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->updateGroup(*oldGroupInfo, groupInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::deleteGroup(unsigned long gid) throw(Core::Exception) { - 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); + boost::shared_ptr<const GroupInfo> groupInfo = dbBackend->getGroupInfo(gid, 0); + if(!groupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->deleteGroup(gid); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->deleteGroup(*groupInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) { - 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); + boost::shared_ptr<const UserInfo> userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + boost::shared_ptr<const GroupInfo> groupInfo = dbBackend->getGroupInfo(gid, 0); + if(!groupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->addUserToGroup(uid, gid); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->addUserToGroup(*userInfo, *groupInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) { - 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); + boost::shared_ptr<const UserInfo> userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + boost::shared_ptr<const GroupInfo> groupInfo = dbBackend->getGroupInfo(gid, 0); + if(!groupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->deleteUserFromGroup(uid, gid); + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->deleteUserFromGroup(*userInfo, *groupInfo); + } + catch(Core::Exception e) { + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } } } |