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/Server/ConnectionManager.cpp | 50 +++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'src/Server/ConnectionManager.cpp') diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index 160f3c3..e52e8c4 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -22,6 +22,7 @@ #include "Application.h" #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include -//#include #include namespace Mad { @@ -42,8 +42,8 @@ bool ConnectionManager::ServerConnection::send(const Net::Packet &packet) { return connection->send(packet); } -ConnectionManager::ServerConnection::ServerConnection(Core::Application *application, boost::shared_ptr connection0) -: Common::Connection(application), connection(connection0), type(UNKNOWN), hostInfo(0) { +ConnectionManager::ServerConnection::ServerConnection(Common::Application *application0, boost::shared_ptr connection0) +: Common::Connection(application0), application(application0), connection(connection0), type(UNKNOWN), hostInfo(0) { connection->connectSignalReceive(boost::bind(&ServerConnection::receive, this, _1)); } @@ -57,6 +57,16 @@ bool ConnectionManager::ServerConnection::disconnect() { return true; } +boost::shared_ptr ConnectionManager::ServerConnection::authenticate(const std::string &method, + const std::string &user, const std::vector &challenge, std::vector &response) { + if(!isIdentified()) + type = CLIENT; + + authContext = application->getAuthManager()->authenticate(method, user, challenge, response, authContext); + + return authContext; +} + /*void* ConnectionManager::ServerConnection::getCertificate(size_t *size) const { const gnutls_datum_t *cert = connection->getCertificate(); @@ -203,7 +213,6 @@ ConnectionManager::ConnectionManager(Application *application0) : application(ap connectionRequestHandlerGroup(new RequestHandlers::ConnectionRequestHandlerGroup(application)), daemonRequestHandlerGroup(new RequestHandlers::DaemonRequestHandlerGroup), userRequestHandlerGroup(new RequestHandlers::UserRequestHandlerGroup(application)) { - //requestManager->registerPacketType("AuthGSSAPI"); application->getRequestManager()->registerPacketType("FSInfo"); application->getRequestManager()->registerPacketType("GetStatus"); @@ -223,12 +232,11 @@ ConnectionManager::~ConnectionManager() { application->getRequestManager()->unregisterRequestHandlerGroup(daemonRequestHandlerGroup); application->getRequestManager()->unregisterRequestHandlerGroup(connectionRequestHandlerGroup); - //requestManager->unregisterPacketType("AuthGSSAPI"); application->getRequestManager()->unregisterPacketType("FSInfo"); application->getRequestManager()->unregisterPacketType("GetStatus"); } -boost::shared_ptr ConnectionManager::getDaemonConnection(const std::string &name) const throw (Core::Exception&) { +boost::shared_ptr ConnectionManager::getDaemonConnection(const std::string &name) const throw (Core::Exception) { std::map::const_iterator hostIt = daemonInfo.find(name); @@ -248,7 +256,7 @@ boost::shared_ptr ConnectionManager::getDaemonConnection(con throw Core::Exception(Core::Exception::NOT_AVAILABLE); } -std::string ConnectionManager::getDaemonName(const Common::Connection *con) const throw (Core::Exception&) { +std::string ConnectionManager::getDaemonName(const Common::Connection *con) const throw (Core::Exception) { const ServerConnection *connection = dynamic_cast(con); if(connection && connection->getConnectionType() == ServerConnection::DAEMON) @@ -257,13 +265,13 @@ std::string ConnectionManager::getDaemonName(const Common::Connection *con) cons throw Core::Exception(Core::Exception::UNKNOWN_DAEMON); } -void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const std::string &name) throw (Core::Exception&) { +void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const std::string &name) throw (Core::Exception) { // TODO Logging ServerConnection *connection = dynamic_cast(con); if(!connection) - throw Core::Exception(Core::Exception::INVALID_ACTION); + throw Core::Exception(Core::Exception::INVALID_INPUT); if(connection->isIdentified()) throw Core::Exception(Core::Exception::ALREADY_IDENTIFIED); @@ -283,20 +291,21 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const connection->identify(hostInfo); updateState(hostInfo, Common::HostInfo::RUNNING); - - application->logf("Identified as '%s'.", name.c_str()); } -void ConnectionManager::identifyClientConnection(Common::Connection *con) throw (Core::Exception&) { +boost::shared_ptr ConnectionManager::authenticateConnection(Common::Connection *con, const std::string &method, + const std::string &user, const std::vector &challenge, std::vector &response) { + // TODO Logging + ServerConnection *connection = dynamic_cast(con); if(!connection) - throw Core::Exception(Core::Exception::INVALID_ACTION); + throw Core::Exception(Core::Exception::INVALID_INPUT); - if(connection->isIdentified()) - throw Core::Exception(Core::Exception::ALREADY_IDENTIFIED); + if(!connection->isIdentified()) + connection->identify(); - connection->identify(); + return connection->authenticate(method, user, challenge, response); } std::vector ConnectionManager::getDaemonList() const { @@ -309,5 +318,14 @@ std::vector ConnectionManager::getDaemonList() const { return ret; } +bool ConnectionManager::isAuthenticated(Common::Connection *con) const { + ServerConnection *connection = dynamic_cast(con); + + if(!connection) + throw Core::Exception(Core::Exception::INVALID_INPUT); + + return connection->isAuthenticated(); +} + } } -- cgit v1.2.3