diff options
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Application.cpp | 4 | ||||
-rw-r--r-- | src/Common/Application.h | 6 | ||||
-rw-r--r-- | src/Common/AuthBackend.h | 53 | ||||
-rw-r--r-- | src/Common/AuthContext.h | 36 | ||||
-rw-r--r-- | src/Common/AuthManager.cpp | 58 | ||||
-rw-r--r-- | src/Common/AuthManager.h | 84 | ||||
-rw-r--r-- | src/Common/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/Common/Connection.h | 12 | ||||
-rw-r--r-- | src/Common/Requests/AuthMethodRequest.h | 38 | ||||
-rw-r--r-- | src/Common/Requests/FSInfoRequest.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/IdentifyRequest.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/StatusRequest.h | 2 |
12 files changed, 283 insertions, 17 deletions
diff --git a/src/Common/Application.cpp b/src/Common/Application.cpp index 38ef4b5..196e57a 100644 --- a/src/Common/Application.cpp +++ b/src/Common/Application.cpp @@ -18,6 +18,7 @@ */ #include "Application.h" +#include "AuthManager.h" #include "ModuleManager.h" #include "RequestManager.h" #include "SystemManager.h" @@ -26,7 +27,7 @@ namespace Mad { namespace Common { -Application::Application(bool server) : moduleManager(new ModuleManager(this)), requestManager(new RequestManager(this, server)), +Application::Application(bool server) : authManager(new AuthManager), moduleManager(new ModuleManager(this)), requestManager(new RequestManager(this, server)), systemManager(new SystemManager), userManager(new UserManager(this)) {} Application::~Application() { @@ -34,6 +35,7 @@ Application::~Application() { delete systemManager; delete requestManager; delete moduleManager; + delete authManager; } } diff --git a/src/Common/Application.h b/src/Common/Application.h index 6de3b07..39cf2de 100644 --- a/src/Common/Application.h +++ b/src/Common/Application.h @@ -27,6 +27,7 @@ namespace Mad { namespace Common { +class AuthManager; class ModuleManager; class RequestManager; class SystemManager; @@ -34,6 +35,7 @@ class UserManager; class MAD_COMMON_EXPORT Application : public Core::Application { private: + AuthManager *authManager; ModuleManager *moduleManager; RequestManager *requestManager; SystemManager *systemManager; @@ -44,6 +46,10 @@ class MAD_COMMON_EXPORT Application : public Core::Application { virtual ~Application(); public: + AuthManager* getAuthManager() const { + return authManager; + } + ModuleManager* getModuleManager() const { return moduleManager; } diff --git a/src/Common/AuthBackend.h b/src/Common/AuthBackend.h new file mode 100644 index 0000000..e933856 --- /dev/null +++ b/src/Common/AuthBackend.h @@ -0,0 +1,53 @@ +/* + * AuthBackend.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_COMMON_AUTHBACKEND_H_ +#define MAD_COMMON_AUTHBACKEND_H_ + +#include <Core/Exception.h> + +#include <vector> + +#include <boost/cstdint.hpp> +#include <boost/shared_ptr.hpp> + +namespace Mad { +namespace Common { + +class AuthContext; +class AuthManager; + +class AuthBackend { + protected: + friend class AuthManager; + + virtual const std::vector<std::string>& getMethods() const = 0; + + virtual boost::shared_ptr<AuthContext> 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) = 0; + + public: + virtual ~AuthBackend() {} +}; + +} +} + +#endif /* MAD_COMMON_AUTHBACKEND_H_ */ diff --git a/src/Common/AuthContext.h b/src/Common/AuthContext.h new file mode 100644 index 0000000..b402dd3 --- /dev/null +++ b/src/Common/AuthContext.h @@ -0,0 +1,36 @@ +/* + * AuthContext.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_COMMON_AUTHCONTEXT_H_ +#define MAD_COMMON_AUTHCONTEXT_H_ + +namespace Mad { +namespace Common { + +class AuthContext { + public: + virtual bool isAuthenticated() const = 0; + + virtual ~AuthContext() {} +}; + +} +} + +#endif /* MAD_COMMON_AUTHCONTEXT_H_ */ 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); +} + +} +} diff --git a/src/Common/AuthManager.h b/src/Common/AuthManager.h new file mode 100644 index 0000000..c773214 --- /dev/null +++ b/src/Common/AuthManager.h @@ -0,0 +1,84 @@ +/* + * AuthManager.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_COMMON_AUTHMANAGER_H_ +#define MAD_COMMON_AUTHMANAGER_H_ + +#include "export.h" + +#include "AuthBackend.h" +#include "AuthContext.h" + +#include <Core/Exception.h> + +#include <vector> + +#include <boost/cstdint.hpp> +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> + +#include <boost/thread/shared_mutex.hpp> + +namespace Mad { +namespace Common { + +class Application; + +class MAD_COMMON_EXPORT AuthManager : private boost::noncopyable { + private: + friend class Application; + + class DenyBackend : public AuthBackend { + private: + const static std::vector<std::string> methods; + + protected: + virtual const std::vector<std::string>& getMethods() const { + return methods; + } + + virtual boost::shared_ptr<AuthContext> 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) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); + } + }; + + boost::shared_ptr<DenyBackend> denyBackend; + + boost::shared_ptr<AuthBackend> backend; + + boost::shared_mutex mutex; + + AuthManager() : denyBackend(new DenyBackend), backend(denyBackend) {} + + public: + void registerBackend(boost::shared_ptr<AuthBackend> newBackend); + void unregisterBackend(boost::shared_ptr<AuthBackend> oldBackend); + + std::vector<std::string> getMethods(); + + boost::shared_ptr<AuthContext> 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 = boost::shared_ptr<AuthContext>()) throw(Core::Exception); +}; + +} +} + +#endif /* MAD_COMMON_AUTHMANAGER_H_ */ diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 4ddcd07..13e1599 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -18,6 +18,9 @@ mad_library(Common Requests/StatusRequest.h Application.cpp Application.h + AuthBackend.h + AuthContext.h + AuthManager.cpp AuthManager.h Base64Encoder.cpp Base64Encoder.h ClientConnection.cpp ClientConnection.h Connection.cpp Connection.h diff --git a/src/Common/Connection.h b/src/Common/Connection.h index e0c9ce6..bcf6c44 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -39,12 +39,10 @@ class XmlPacket; class MAD_COMMON_EXPORT Connection : private boost::noncopyable { private: - bool authenticated; - Core::Signals::Signal2<boost::shared_ptr<const XmlPacket>, boost::uint16_t> signalReceive; protected: - Connection(Core::Application *application) : authenticated(0), signalReceive(application) {} + Connection(Core::Application *application) : signalReceive(application) {} void receive(boost::shared_ptr<Net::Packet> packet); @@ -66,14 +64,6 @@ class MAD_COMMON_EXPORT Connection : private boost::noncopyable { virtual bool disconnect() = 0; //virtual void* getCertificate(size_t *size) const = 0; //virtual void* getPeerCertificate(size_t *size) const = 0; - - void setAuthenticated() { - authenticated = true; - } - - bool isAuthenticated() const { - return authenticated; - } }; } diff --git a/src/Common/Requests/AuthMethodRequest.h b/src/Common/Requests/AuthMethodRequest.h new file mode 100644 index 0000000..e8199fd --- /dev/null +++ b/src/Common/Requests/AuthMethodRequest.h @@ -0,0 +1,38 @@ +/* + * AuthMethodRequest.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_COMMON_REQUESTS_AUTHMETHODREQUEST_H_ +#define MAD_COMMON_REQUESTS_AUTHMETHODREQUEST_H_ + +#include "SimpleRequest.h" + +namespace Mad { +namespace Common { +namespace Requests { + +class AuthMethodRequest : public SimpleRequest { + public: + AuthMethodRequest(Application *application) : SimpleRequest(application, "GetAuthMethods") {} +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTS_AUTHMETHODREQUEST_H_ */ diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h index 14aff57..223b7a4 100644 --- a/src/Common/Requests/FSInfoRequest.h +++ b/src/Common/Requests/FSInfoRequest.h @@ -20,8 +20,6 @@ #ifndef MAD_COMMON_REQUESTS_FSINFOREQUEST_H_ #define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_ -#include "../export.h" - #include "SimpleRequest.h" namespace Mad { diff --git a/src/Common/Requests/IdentifyRequest.h b/src/Common/Requests/IdentifyRequest.h index e2e1399..51b24dd 100644 --- a/src/Common/Requests/IdentifyRequest.h +++ b/src/Common/Requests/IdentifyRequest.h @@ -38,7 +38,7 @@ class MAD_COMMON_EXPORT IdentifyRequest : public Common::Request { virtual void sendRequest(); public: - IdentifyRequest(Application *application, const std::string &hostname0 = std::string()) : Request(application), hostname(hostname0) {} + IdentifyRequest(Application *application, const std::string &hostname0) : Request(application), hostname(hostname0) {} }; } diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h index 0569a72..09f4d90 100644 --- a/src/Common/Requests/StatusRequest.h +++ b/src/Common/Requests/StatusRequest.h @@ -20,8 +20,6 @@ #ifndef MAD_COMMON_REQUESTS_STATUSREQUEST_H_ #define MAD_COMMON_REQUESTS_STATUSREQUEST_H_ -#include "../export.h" - #include "SimpleRequest.h" namespace Mad { |