From df114cc52f48645c9c6736faceef8920c9441cbe Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 15 Jul 2009 23:55:55 +0200 Subject: UserManager: Benutze UserConfigBackends --- src/Common/UserManager.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 8 deletions(-) (limited to 'src/Common/UserManager.cpp') 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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); dbBackend->addUser(userInfo); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + boost::shared_ptr oldUserInfo = dbBackend->getUserInfo(uid, 0); + if(!oldUserInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->updateUser(uid, userInfo); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + boost::shared_ptr userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->deleteUser(uid); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); dbBackend->addGroup(groupInfo); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + boost::shared_ptr oldGroupInfo = dbBackend->getGroupInfo(gid, 0); + if(!oldGroupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->updateGroup(gid, groupInfo); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + boost::shared_ptr groupInfo = dbBackend->getGroupInfo(gid, 0); + if(!groupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->deleteGroup(gid); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + boost::shared_ptr userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + boost::shared_ptr groupInfo = dbBackend->getGroupInfo(gid, 0); + if(!groupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->addUserToGroup(uid, gid); + + for(std::set >::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 lock(mutex); + boost::lock_guard lock(mutex); if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + boost::shared_ptr userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + boost::shared_ptr groupInfo = dbBackend->getGroupInfo(gid, 0); + if(!groupInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + dbBackend->deleteUserFromGroup(uid, gid); + + for(std::set >::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()); + } + } } } -- cgit v1.2.3