/* * 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 "UserCache.h" #include 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()); } void UserManager::registerBackendCached(boost::shared_ptr backend) { { boost::lock_guard lock(mutex); backends.insert(std::make_pair(backend, boost::shared_ptr(new UserCache(backend)))); } } boost::shared_ptr > UserManager::getUserList() throw(Core::Exception) { Core::Exception e(Core::Exception::NOT_IMPLEMENTED); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->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); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->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); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->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); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->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); boost::shared_ptr > ret; { boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->getGroupList(); } 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::getGroupInfo(unsigned long gid) throw(Core::Exception) { Core::Exception e(Core::Exception::NOT_IMPLEMENTED); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->getGroupInfo(gid); } 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::getGroupInfoByName(const std::string &name) throw(Core::Exception) { Core::Exception e(Core::Exception::NOT_IMPLEMENTED); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->getGroupInfoByName(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); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->getGroupUserList(gid); } 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::getFullUserGroupList() throw(Core::Exception) { Core::Exception e(Core::Exception::NOT_IMPLEMENTED); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { return backend->second->getFullUserGroupList(); } 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); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { backend->second->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); boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { backend->second->addUser(userInfo); } catch(Core::Exception e2) { if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } throw e; } } }