diff options
Diffstat (limited to 'src/Common/AuthManager.cpp')
-rw-r--r-- | src/Common/AuthManager.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Common/AuthManager.cpp b/src/Common/AuthManager.cpp new file mode 100644 index 0000000..b27c29f --- /dev/null +++ b/src/Common/AuthManager.cpp @@ -0,0 +1,58 @@ +/* + * AuthManager.cpp + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "AuthManager.h" + +#include "AuthBackend.h" + +namespace Mad { +namespace Common { + +const std::vector<std::string> AuthManager::DenyBackend::methods; + +void AuthManager::registerBackend(boost::shared_ptr<AuthBackend> newBackend) { + boost::lock_guard<boost::shared_mutex> lock(mutex); + + backend = newBackend; +} + +void AuthManager::unregisterBackend(boost::shared_ptr<AuthBackend> oldBackend) { + boost::lock_guard<boost::shared_mutex> lock(mutex); + + if(oldBackend == backend) + backend = denyBackend; +} + +std::vector<std::string> AuthManager::getMethods() { + boost::shared_lock<boost::shared_mutex> lock(mutex); + + return backend->getMethods(); +} + +boost::shared_ptr<AuthContext> AuthManager::authenticate(const std::string &method, const std::string &user, const std::vector<boost::uint8_t> &challenge, + std::vector<boost::uint8_t> &response, boost::shared_ptr<AuthContext> context) throw(Core::Exception) { + boost::lock_guard<boost::shared_mutex> lock(mutex); + + response.clear(); + + return backend->authenticate(method, user, challenge, response, context); +} + +} +} |