diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-08-27 17:27:58 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-08-27 17:27:58 +0200 |
commit | 82ef58fb3d0bdf6ce7d13f42cca30d03b24973c6 (patch) | |
tree | 4508a31968224772e70fd9df38f11b3a2461c55e /src/modules/AuthBackendFile | |
parent | 854e90be061166d1619a74cbfdc7e384fc700125 (diff) | |
download | mad-82ef58fb3d0bdf6ce7d13f42cca30d03b24973c6.tar mad-82ef58fb3d0bdf6ce7d13f42cca30d03b24973c6.zip |
AuthProvider hinzugefügt
AuthBackendFile in AuthProviderFile und AuthBackendPassword aufgeteilt
Diffstat (limited to 'src/modules/AuthBackendFile')
-rw-r--r-- | src/modules/AuthBackendFile/AuthBackendFile.cpp | 108 | ||||
-rw-r--r-- | src/modules/AuthBackendFile/AuthBackendFile.h | 95 | ||||
-rw-r--r-- | src/modules/AuthBackendFile/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/modules/AuthBackendFile/Module.cpp | 30 | ||||
-rw-r--r-- | src/modules/AuthBackendFile/Module.h | 52 |
5 files changed, 0 insertions, 293 deletions
diff --git a/src/modules/AuthBackendFile/AuthBackendFile.cpp b/src/modules/AuthBackendFile/AuthBackendFile.cpp deleted file mode 100644 index b05b2db..0000000 --- a/src/modules/AuthBackendFile/AuthBackendFile.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * AuthBackendFile.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 "AuthBackendFile.h" -#include <Core/ConfigEntry.h> -#include <Core/ConfigManager.h> - -#include <fstream> - -#include <boost/regex.hpp> - -namespace Mad { -namespace Modules { -namespace AuthBackendFile { - -void AuthBackendFile::readFile(const std::string &name) { - std::ifstream stream(name.c_str()); - if(!stream.good()) { - application->logf(Core::LoggerBase::LOG_WARNING, "AuthBackendFile: Can't read file '%s'.", name.c_str()); - return; - } - - while(stream.good() && !stream.eof()) { - std::string line; - std::getline(stream, line); - - if(line.empty()) - continue; - - static const boost::regex regex("([^:]+):(.+)", boost::regex_constants::perl); - boost::smatch match; - - if(!boost::regex_match(line, match, regex)) { - application->logf(Core::LoggerBase::LOG_WARNING, "AuthBackendFile: Malformed line in file '%s'.", name.c_str()); - continue; - } - - - userMap.insert(std::make_pair(match[1].str(), match[2].str())); - } -} - -bool AuthBackendFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/) { - if(!entry[0].getKey().matches("AuthBackendFile")) - return false; - - if(entry[1].empty()) - return true; - - if(entry[1].getKey().matches("File")) { - if(entry[2].empty()) { - readFile(entry[1][0]); - } - } - else if(!entry[2].empty()) - return false; - - return true; -} - -boost::shared_ptr<Common::AuthContext> AuthBackendFile::authenticate(const std::string &method, const std::string &subMethod, - const std::string &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t>& /*response*/, - boost::shared_ptr<Common::AuthContext> context) throw(Core::Exception) { - if(method != "Password") - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - - if(context.get() != 0 && dynamic_cast<AuthContextFile*>(context.get()) == 0) - throw(Core::Exception(Core::Exception::INVALID_INPUT)); - - if(context.get() == 0) - context.reset(new AuthContextFile); - - std::map<std::string, std::string>::iterator userIt = userMap.find(user); - if(userIt == userMap.end()) - throw(Core::Exception(Core::Exception::AUTHENTICATION)); - - if(subMethod == "Clear") { - if(userIt->second != std::string(data.begin(), data.end())) - throw(Core::Exception(Core::Exception::AUTHENTICATION)); - } - else { - if(!std::equal(data.begin(), data.end(), Common::Hash::hash(userIt->second, subMethod).begin())) - throw(Core::Exception(Core::Exception::AUTHENTICATION)); - } - - - return context; -} - -} -} -} diff --git a/src/modules/AuthBackendFile/AuthBackendFile.h b/src/modules/AuthBackendFile/AuthBackendFile.h deleted file mode 100644 index 8098817..0000000 --- a/src/modules/AuthBackendFile/AuthBackendFile.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * AuthBackendFile.h - * - * Copyright (C) 2008 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/>. - */ - -#ifndef MAD_MODULES_AUTHBACKENDFILE_AUTHBACKENDFILE_H_ -#define MAD_MODULES_AUTHBACKENDFILE_AUTHBACKENDFILE_H_ - -#include "../export.h" - -#include <Common/AuthBackend.h> -#include <Common/AuthContext.h> -#include <Common/Application.h> -#include <Common/Hash.h> - -#include <Core/Configurable.h> -#include <Core/ConfigManager.h> - -namespace Mad { -namespace Modules { -namespace AuthBackendFile { - -class MAD_MODULE_EXPORT AuthBackendFile : public Common::AuthBackend, private Core::Configurable, private boost::noncopyable { - private: - class AuthContextFile : public Common::AuthContext { - protected: - virtual bool isAuthenticated() const { - return true; - } - }; - - void readFile(const std::string &name); - - Common::Application *application; - - std::vector<std::string> methods; - std::vector<std::string> subMethods; - - std::map<std::string, std::string> userMap; - - protected: - virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/); - - virtual const std::vector<std::string>& getMethods() const { - return methods; - } - - virtual const std::vector<std::string>& getSubMethods(const std::string &method) const throw(Core::Exception) { - if(method != "Password") - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - - return subMethods; - } - - virtual boost::shared_ptr<Common::AuthContext> authenticate(const std::string &method, const std::string &subMethod, - const std::string &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, - boost::shared_ptr<Common::AuthContext> context) throw(Core::Exception); - - public: - AuthBackendFile(Common::Application *application0) : application(application0) { - methods.push_back("Password"); - - const std::vector<std::string> &hashList = Common::Hash::getHashList(); - if(hashList.empty()) - subMethods.push_back("Clear"); - else - subMethods.push_back(hashList.front()); - - application->getConfigManager()->registerConfigurable(this); - } - - virtual ~AuthBackendFile() { - application->getConfigManager()->unregisterConfigurable(this); - } -}; - -} -} -} - -#endif /* MAD_MODULES_AUTHBACKENDFILE_AUTHBACKENDFILE_H_ */ diff --git a/src/modules/AuthBackendFile/CMakeLists.txt b/src/modules/AuthBackendFile/CMakeLists.txt deleted file mode 100644 index 3afd71f..0000000 --- a/src/modules/AuthBackendFile/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -include_directories(${INCLUDES}) - -mad_module(AuthBackendFile - Module.cpp Module.h - AuthBackendFile.cpp AuthBackendFile.h -) - -mad_module_libraries(AuthBackendFile) diff --git a/src/modules/AuthBackendFile/Module.cpp b/src/modules/AuthBackendFile/Module.cpp deleted file mode 100644 index e5a9a18..0000000 --- a/src/modules/AuthBackendFile/Module.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Module.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 "../export.h" - -#include "Module.h" - -extern "C" { - -MAD_MODULE_EXPORT Mad::Common::Module* AuthBackendFile_create(Mad::Common::Application *application) { - return new Mad::Modules::AuthBackendFile::Module(application); -} - -} diff --git a/src/modules/AuthBackendFile/Module.h b/src/modules/AuthBackendFile/Module.h deleted file mode 100644 index b0d14aa..0000000 --- a/src/modules/AuthBackendFile/Module.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Module.h - * - * 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/>. - */ - -#ifndef MAD_MODULES_AUTHBACKENDFILE_MODULE_H_ -#define MAD_MODULES_AUTHBACKENDFILE_MODULE_H_ - -#include "AuthBackendFile.h" - -#include <Common/Module.h> -#include <Common/AuthManager.h> - -namespace Mad { -namespace Modules { -namespace AuthBackendFile { - -class Module : public Common::Module { - private: - Common::Application *application; - - boost::shared_ptr<AuthBackendFile> backend; - - public: - Module(Common::Application *application0) : application(application0), backend(new AuthBackendFile(application)) { - application->getAuthManager()->registerBackend(backend); - } - - virtual ~Module() { - application->getAuthManager()->unregisterBackend(backend); - } -}; - -} -} -} - -#endif /* MAD_MODULES_AUTHBACKENDFILE_MODULE_H_ */ |