/* * AuthManager.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 Lesser 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program. If not, see . */ #include "AuthManager.h" #include "AuthBackend.h" #include namespace Mad { namespace Common { void AuthManager::setProvider(boost::shared_ptr newProvider) { boost::lock_guard lock(mutex); provider = newProvider; } void AuthManager::unsetProvider(boost::shared_ptr oldProvider) { boost::lock_guard lock(mutex); if(oldProvider == provider) provider.reset(); } void AuthManager::registerBackend(boost::shared_ptr backend) { boost::lock_guard lock(mutex); methods.insert(backend->getMethodName()); backends.insert(std::make_pair(backend->getMethodName(), backend)); } void AuthManager::unregisterBackend(boost::shared_ptr backend) { boost::lock_guard lock(mutex); std::map >::iterator backendIt = backends.find(backend->getMethodName()); if(backendIt == backends.end() || backendIt->second != backend) return; methods.erase(backend->getMethodName()); backends.erase(backendIt); } const std::set& AuthManager::getMethods() { boost::shared_lock lock(mutex); return methods; } std::vector AuthManager::getSubMethods(const Core::String &method) throw(Core::Exception) { boost::shared_lock lock(mutex); std::map >::iterator backend = backends.find(method); if(backend == backends.end()) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); if(!provider) throw Core::Exception(Core::Exception::NOT_AVAILABLE); return backend->second->getSubMethods(provider); } boost::shared_ptr AuthManager::authenticate(const Core::String &method, const Core::String &subMethod, const Core::String &user, const std::vector &data, std::vector &response, boost::shared_ptr context) throw(Core::Exception) { std::map >::iterator backend; { boost::lock_guard lock(mutex); response.clear(); backend = backends.find(method); if(backend == backends.end()) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); if(!provider) throw Core::Exception(Core::Exception::NOT_AVAILABLE); } return backend->second->authenticate(provider, subMethod, user, data, response, context); } } }