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 --- .../ConnectionRequestHandlerGroup.cpp | 45 +++++++++++++++++++--- .../ConnectionRequestHandlerGroup.h | 2 + .../RequestHandlers/DaemonRequestHandlerGroup.cpp | 7 +++- .../RequestHandlers/DaemonRequestHandlerGroup.h | 2 - 4 files changed, 46 insertions(+), 10 deletions(-) (limited to 'src/Server/RequestHandlers') diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp index e94853f..b59cc3d 100644 --- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp @@ -21,6 +21,8 @@ #include "../Application.h" #include "../ConnectionManager.h" +#include + #include #include @@ -29,9 +31,41 @@ namespace Mad { namespace Server { namespace RequestHandlers { -void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret, +void ConnectionRequestHandlerGroup::handleAuthMethodRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret, Common::Connection* /*connection*/) { - // TODO Require authentication + ret->setType("OK"); + + Common::XmlPacket::List *list = ret->createList("methods"); + + const std::vector &methods = application->getAuthManager()->getMethods(); + + for(std::vector::const_iterator method = methods.begin(); method != methods.end(); ++method) { + Common::XmlPacket::List::iterator entry = list->addEntry(); + + entry->set("name", *method); + } +} + +void ConnectionRequestHandlerGroup::handleAuthRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { + std::vector response; + + boost::shared_ptr authContext = application->getConnectionManager()->authenticateConnection(connection, + packet->get("method"), packet->get("user"), + packet->get&>("challenge"), response); + + if(!response.empty()) + ret->set("response", response); + + if(authContext->isAuthenticated()) + ret->setType("OK"); + else + ret->setType("Continue"); +} + +void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret, + Common::Connection *connection) { + if(!application->getConnectionManager()->isAuthenticated(connection)) + throw(Core::Exception(Core::Exception::PERMISSION)); ret->setType("OK"); Common::XmlPacket::List *list = ret->createList("hosts"); @@ -48,10 +82,7 @@ void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(packet->get("hostname").empty()) - application->getConnectionManager()->identifyClientConnection(connection); - else - application->getConnectionManager()->identifyDaemonConnection(connection, packet->get("hostname")); + application->getConnectionManager()->identifyDaemonConnection(connection, packet->get("hostname")); ret->setType("OK"); } @@ -85,6 +116,8 @@ void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleAuthRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); void handleDaemonListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); void handleIdentifyRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); void handleLogRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp index 0345d7b..ee79ff2 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp @@ -44,10 +44,13 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared return; } - // TODO Require authentication + ConnectionManager *connectionManager = dynamic_cast(*getApplication()).getConnectionManager(); + + if(!connectionManager->isAuthenticated(getConnection())) + throw(Core::Exception(Core::Exception::PERMISSION)); try { - boost::shared_ptr daemonCon = dynamic_cast(*getApplication()).getConnectionManager()->getDaemonConnection(packet->get("daemon")); + boost::shared_ptr daemonCon = connectionManager->getDaemonConnection(packet->get("daemon")); boost::shared_ptr request; if(type == "DaemonCommand") diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h index 086bf16..8312709 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h @@ -47,8 +47,6 @@ class MAD_SERVER_EXPORT DaemonRequestHandlerGroup : public Common::RequestHandle : Common::RequestHandler(application), type(type0) {} }; - ConnectionManager *connectionManager; - std::set types; public: -- cgit v1.2.3