summaryrefslogtreecommitdiffstats
path: root/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp')
-rw-r--r--src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp45
1 files changed, 39 insertions, 6 deletions
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 <Common/AuthManager.h>
+
#include <Core/LogManager.h>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -29,9 +31,41 @@ namespace Mad {
namespace Server {
namespace RequestHandlers {
-void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr<const Common::XmlPacket> /*packet*/, Common::XmlPacket *ret,
+void ConnectionRequestHandlerGroup::handleAuthMethodRequest(boost::shared_ptr<const Common::XmlPacket> /*packet*/, Common::XmlPacket *ret,
Common::Connection* /*connection*/) {
- // TODO Require authentication
+ ret->setType("OK");
+
+ Common::XmlPacket::List *list = ret->createList("methods");
+
+ const std::vector<std::string> &methods = application->getAuthManager()->getMethods();
+
+ for(std::vector<std::string>::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<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection) {
+ std::vector<boost::uint8_t> response;
+
+ boost::shared_ptr<const Common::AuthContext> authContext = application->getConnectionManager()->authenticateConnection(connection,
+ packet->get<const std::string&>("method"), packet->get<const std::string&>("user"),
+ packet->get<const std::vector<boost::uint8_t>&>("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<const Common::XmlPacket> /*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<co
}
void ConnectionRequestHandlerGroup::handleIdentifyRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection) {
- if(packet->get<const std::string&>("hostname").empty())
- application->getConnectionManager()->identifyClientConnection(connection);
- else
- application->getConnectionManager()->identifyDaemonConnection(connection, packet->get<const std::string&>("hostname"));
+ application->getConnectionManager()->identifyDaemonConnection(connection, packet->get<const std::string&>("hostname"));
ret->setType("OK");
}
@@ -85,6 +116,8 @@ void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr<const Com
}
ConnectionRequestHandlerGroup::ConnectionRequestHandlerGroup(Application *application0) : application(application0) {
+ registerHandler("GetAuthMethods", boost::bind(&ConnectionRequestHandlerGroup::handleAuthMethodRequest, this, _1, _2, _3));
+ registerHandler("Authenticate", boost::bind(&ConnectionRequestHandlerGroup::handleAuthRequest, this, _1, _2, _3));
registerHandler("ListHosts", boost::bind(&ConnectionRequestHandlerGroup::handleDaemonListRequest, this, _1, _2, _3));
registerHandler("Identify", boost::bind(&ConnectionRequestHandlerGroup::handleIdentifyRequest, this, _1, _2, _3));
registerHandler("Log", boost::bind(&ConnectionRequestHandlerGroup::handleLogRequest, this, _1, _2, _3));