From 415cd36477e152c12f91a10ad61bb719373cd9d1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 23 Aug 2009 20:57:00 +0200 Subject: =?UTF-8?q?Authentifikation=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Application.cpp | 4 +- src/Common/Application.h | 6 +++ src/Common/AuthBackend.h | 53 +++++++++++++++++++++ src/Common/AuthContext.h | 36 ++++++++++++++ src/Common/AuthManager.cpp | 58 +++++++++++++++++++++++ src/Common/AuthManager.h | 84 +++++++++++++++++++++++++++++++++ src/Common/CMakeLists.txt | 3 ++ src/Common/Connection.h | 12 +---- src/Common/Requests/AuthMethodRequest.h | 38 +++++++++++++++ src/Common/Requests/FSInfoRequest.h | 2 - src/Common/Requests/IdentifyRequest.h | 2 +- src/Common/Requests/StatusRequest.h | 2 - 12 files changed, 283 insertions(+), 17 deletions(-) create mode 100644 src/Common/AuthBackend.h create mode 100644 src/Common/AuthContext.h create mode 100644 src/Common/AuthManager.cpp create mode 100644 src/Common/AuthManager.h create mode 100644 src/Common/Requests/AuthMethodRequest.h (limited to 'src/Common') 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 + * + * 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 . + */ + +#ifndef MAD_COMMON_AUTHBACKEND_H_ +#define MAD_COMMON_AUTHBACKEND_H_ + +#include + +#include + +#include +#include + +namespace Mad { +namespace Common { + +class AuthContext; +class AuthManager; + +class AuthBackend { + protected: + friend class AuthManager; + + virtual const std::vector& getMethods() const = 0; + + virtual boost::shared_ptr authenticate(const std::string& /*method*/, const std::string& /*user*/, + const std::vector& /*challenge*/, std::vector& /*response*/, + boost::shared_ptr /*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 + * + * 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 . + */ + +#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 + * + * 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" + +namespace Mad { +namespace Common { + +const std::vector AuthManager::DenyBackend::methods; + +void AuthManager::registerBackend(boost::shared_ptr newBackend) { + boost::lock_guard lock(mutex); + + backend = newBackend; +} + +void AuthManager::unregisterBackend(boost::shared_ptr oldBackend) { + boost::lock_guard lock(mutex); + + if(oldBackend == backend) + backend = denyBackend; +} + +std::vector AuthManager::getMethods() { + boost::shared_lock lock(mutex); + + return backend->getMethods(); +} + +boost::shared_ptr AuthManager::authenticate(const std::string &method, const std::string &user, const std::vector &challenge, + std::vector &response, boost::shared_ptr context) throw(Core::Exception) { + boost::lock_guard 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 + * + * 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 . + */ + +#ifndef MAD_COMMON_AUTHMANAGER_H_ +#define MAD_COMMON_AUTHMANAGER_H_ + +#include "export.h" + +#include "AuthBackend.h" +#include "AuthContext.h" + +#include + +#include + +#include +#include +#include + +#include + +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 methods; + + protected: + virtual const std::vector& getMethods() const { + return methods; + } + + virtual boost::shared_ptr authenticate(const std::string& /*method*/, const std::string& /*user*/, + const std::vector& /*challenge*/, std::vector& /*response*/, + boost::shared_ptr /*context*/) throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); + } + }; + + boost::shared_ptr denyBackend; + + boost::shared_ptr backend; + + boost::shared_mutex mutex; + + AuthManager() : denyBackend(new DenyBackend), backend(denyBackend) {} + + public: + void registerBackend(boost::shared_ptr newBackend); + void unregisterBackend(boost::shared_ptr oldBackend); + + std::vector getMethods(); + + boost::shared_ptr authenticate(const std::string &method, const std::string &user, const std::vector &challenge, + std::vector &response, boost::shared_ptr context = boost::shared_ptr()) 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::uint16_t> signalReceive; protected: - Connection(Core::Application *application) : authenticated(0), signalReceive(application) {} + Connection(Core::Application *application) : signalReceive(application) {} void receive(boost::shared_ptr 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 + * + * 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 . + */ + +#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 { -- cgit v1.2.3