From 053843f893dd5c96a88e285cf2a5b35419f7dfca Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 31 Aug 2009 18:11:46 +0200 Subject: Immer Authentifizierung fordern --- src/Client/InformationManager.cpp | 3 +- src/Common/ClientConnection.h | 5 +++ src/Common/Connection.h | 3 ++ .../RequestHandlers/FSInfoRequestHandler.cpp | 3 +- .../RequestHandlers/SimpleRequestHandler.cpp | 2 -- .../RequestHandlers/SimpleRequestHandlerGroup.cpp | 2 -- .../RequestHandlers/StatusRequestHandler.cpp | 3 +- .../RequestHandlers/CommandRequestHandler.cpp | 3 +- src/Server/ConnectionManager.cpp | 9 ------ src/Server/ConnectionManager.h | 4 +-- .../ConnectionRequestHandlerGroup.cpp | 2 +- .../RequestHandlers/DaemonRequestHandlerGroup.cpp | 6 ++-- .../RequestHandlers/UserRequestHandlerGroup.cpp | 36 +++++++++++----------- 13 files changed, 39 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 108a2a5..6ac2647 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -28,7 +28,8 @@ namespace Mad { namespace Client { void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret) { - // TODO Require authentication + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); InformationManager *informationManager = dynamic_cast(*getApplication()).getInformationManager(); diff --git a/src/Common/ClientConnection.h b/src/Common/ClientConnection.h index a02c461..7bdceba 100644 --- a/src/Common/ClientConnection.h +++ b/src/Common/ClientConnection.h @@ -54,6 +54,11 @@ class MAD_COMMON_EXPORT ClientConnection : public Connection { void waitWhileConnected() const; virtual bool disconnect(); + + virtual bool isAuthenticated() const { + return true; + } + //virtual void* getCertificate(size_t *size) const; //virtual void* getPeerCertificate(size_t *size) const; }; diff --git a/src/Common/Connection.h b/src/Common/Connection.h index bcf6c44..2a04de0 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -62,6 +62,9 @@ class MAD_COMMON_EXPORT Connection : private boost::noncopyable { virtual bool disconnect() = 0; + + virtual bool isAuthenticated() const = 0; + //virtual void* getCertificate(size_t *size) const = 0; //virtual void* getPeerCertificate(size_t *size) const = 0; }; diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp index 8af1ed3..a416af4 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp @@ -25,7 +25,8 @@ namespace Common { namespace RequestHandlers { void FSInfoRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret) { - // TODO Require authentication + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); std::vector fsInfo; getApplication()->getSystemManager()->getFSInfo(&fsInfo); diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp index 84258a6..789db9e 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp @@ -39,8 +39,6 @@ void SimpleRequestHandler::handlePacket(boost::shared_ptr packe return; } - // TODO Require authentication - XmlPacket ret; try { diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp index f084ac1..261950d 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp @@ -40,8 +40,6 @@ void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ return; } - // TODO Require authentication - XmlPacket ret; try { diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index 18b8868..e5d87da 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -25,7 +25,8 @@ namespace Common { namespace RequestHandlers { void StatusRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret) { - // TODO Require authentication + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); ret->setType("OK"); diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp index 9be8a5b..6c245f9 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp @@ -25,7 +25,8 @@ namespace Daemon { namespace RequestHandlers { void CommandRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret) { - // TODO Require authentication + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); std::string command = packet->get("command"); diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index cb7376c..4867464 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -324,14 +324,5 @@ 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(); -} - } } diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h index 057e73e..099072c 100644 --- a/src/Server/ConnectionManager.h +++ b/src/Server/ConnectionManager.h @@ -97,7 +97,7 @@ class MAD_SERVER_EXPORT ConnectionManager : public Core::Configurable, private b hostInfo = info; } - bool isAuthenticated() const { + virtual bool isAuthenticated() const { return (authContext.get() != 0 && authContext->isAuthenticated()); } @@ -145,8 +145,6 @@ class MAD_SERVER_EXPORT ConnectionManager : public Core::Configurable, private b boost::shared_ptr authenticateConnection(Common::Connection *con, const std::string &method, const std::string &subMethod, const std::string &user, const std::vector &data, std::vector &response); - bool isAuthenticated(Common::Connection *con) const; - std::vector getDaemonList() const; }; diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp index 2a091e6..2171deb 100644 --- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp @@ -74,7 +74,7 @@ void ConnectionRequestHandlerGroup::handleAuthRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); ret->setType("OK"); diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp index ee79ff2..35e167e 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp @@ -44,12 +44,12 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared return; } - ConnectionManager *connectionManager = dynamic_cast(*getApplication()).getConnectionManager(); - - if(!connectionManager->isAuthenticated(getConnection())) + if(!getConnection()->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); try { + ConnectionManager *connectionManager = dynamic_cast(*getApplication()).getConnectionManager(); + boost::shared_ptr daemonCon = connectionManager->getDaemonConnection(packet->get("daemon")); boost::shared_ptr request; diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp index ea6f6c1..d5f97a9 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp @@ -31,7 +31,7 @@ namespace RequestHandlers { void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -67,7 +67,7 @@ void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -103,7 +103,7 @@ void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -136,7 +136,7 @@ void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -170,7 +170,7 @@ void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -204,7 +204,7 @@ void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -235,7 +235,7 @@ void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); @@ -270,7 +270,7 @@ void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); Common::UserInfo userInfo(packet->get("uid"), packet->get("username")); @@ -284,7 +284,7 @@ void UserRequestHandlerGroup::handleUserInfoCheckRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); Common::UserInfo userInfo(packet->get("uid"), packet->get("username")); @@ -298,7 +298,7 @@ void UserRequestHandlerGroup::handleUserAddRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); Common::UserInfo userInfo(packet->get("uid"), packet->get("username")); @@ -312,7 +312,7 @@ void UserRequestHandlerGroup::handleUserUpdateRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->deleteUser(packet->get("uid")); @@ -323,7 +323,7 @@ void UserRequestHandlerGroup::handleUserDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->checkGroupInfo(Common::GroupInfo(packet->get("gid"), packet->get("name"))); @@ -333,7 +333,7 @@ void UserRequestHandlerGroup::handleGroupInfoCheckRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->addGroup(Common::GroupInfo(packet->get("gid"), packet->get("name"))); @@ -343,7 +343,7 @@ void UserRequestHandlerGroup::handleGroupAddRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->updateGroup(packet->get("origGid"), @@ -354,7 +354,7 @@ void UserRequestHandlerGroup::handleGroupUpdateRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->deleteGroup(packet->get("gid")); @@ -365,7 +365,7 @@ void UserRequestHandlerGroup::handleGroupDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->addUserToGroup(packet->get("uid"), packet->get("gid")); @@ -375,7 +375,7 @@ void UserRequestHandlerGroup::handleAddUserToGroupRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->deleteUserFromGroup(packet->get("uid"), packet->get("gid")); @@ -385,7 +385,7 @@ void UserRequestHandlerGroup::handleDeleteUserFromGroupRequest(boost::shared_ptr void UserRequestHandlerGroup::handlePasswordSetRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { - if(!application->getConnectionManager()->isAuthenticated(connection)) + if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); application->getUserManager()->setPassword(packet->get("uid"), packet->get("password")); -- cgit v1.2.3