From f7d433e6e8559b4584263cae025d3addd1342df4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 5 Aug 2009 23:55:44 +0200 Subject: =?UTF-8?q?UserManager:=20Check-Funktionen=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Backends/NetworkUserBackend.cpp | 87 +++++++++++++++++++++++++++++- src/Common/Backends/NetworkUserBackend.h | 37 ++++++++++++- src/Common/UserCache.h | 11 ++++ src/Common/UserConfigBackend.h | 4 ++ src/Common/UserDBBackend.h | 10 ++-- src/Common/UserManager.cpp | 35 ++++++++++++ src/Common/UserManager.h | 8 +-- 7 files changed, 182 insertions(+), 10 deletions(-) (limited to 'src/Common') diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index 39f4e5b..da964e7 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -62,7 +62,7 @@ void NetworkUserBackend::NameUserRequest::sendRequest() { void NetworkUserBackend::UserAddRequest::sendRequest() { XmlPacket packet; - packet.setType("AddUser"); + packet.setType(check ? "CheckUserInfo" : "AddUser"); packet.set("uid", userInfo.getUid()); packet.set("gid", userInfo.getGid()); @@ -85,6 +85,27 @@ void NetworkUserBackend::UserUpdateRequest::sendRequest() { sendPacket(packet); } +void NetworkUserBackend::GroupAddRequest::sendRequest() { + XmlPacket packet; + packet.setType(check ? "CheckGroupInfo" : "AddGroup"); + + packet.set("gid", groupInfo.getGid()); + packet.set("name", groupInfo.getName()); + + sendPacket(packet); +} + +void NetworkUserBackend::GroupUpdateRequest::sendRequest() { + XmlPacket packet; + packet.setType("UpdateGroup"); + + packet.set("origGid", gid); + packet.set("gid", groupInfo.getGid()); + packet.set("name", groupInfo.getName()); + + sendPacket(packet); +} + void NetworkUserBackend::UserGroupRequest::sendRequest() { XmlPacket packet; packet.setType(type); @@ -381,10 +402,22 @@ boost::shared_ptr > NetworkUse }*/ +void NetworkUserBackend::checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::shared_ptr request(new UserAddRequest(application, userInfo, true)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); + + std::pair, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} + void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) { application->getThreadManager()->detach(); - boost::shared_ptr request(new UserAddRequest(application, userInfo)); + boost::shared_ptr request(new UserAddRequest(application, userInfo, false)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -417,6 +450,56 @@ void NetworkUserBackend::deleteUser(unsigned long uid) throw(Core::Exception) { throw result.second; } + +void NetworkUserBackend::checkGroupInfo(const GroupInfo &groupInfo) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::shared_ptr request(new GroupAddRequest(application, groupInfo, true)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); + + std::pair, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} + +void NetworkUserBackend::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::shared_ptr request(new GroupAddRequest(application, groupInfo, false)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); + + std::pair, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} + +void NetworkUserBackend::updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::shared_ptr request(new GroupUpdateRequest(application, gid, groupInfo)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); + + std::pair, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} + +void NetworkUserBackend::deleteGroup(unsigned long gid) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::shared_ptr request(new IdUserRequest(application, "DeleteGroup", "gid", gid)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); + + std::pair, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} + + void NetworkUserBackend::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) { application->getThreadManager()->detach(); diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h index 6c0e94d..a3fa1a6 100644 --- a/src/Common/Backends/NetworkUserBackend.h +++ b/src/Common/Backends/NetworkUserBackend.h @@ -74,13 +74,14 @@ class NetworkUserBackend : public UserDBBackend { class UserAddRequest : public Request { private: UserInfo userInfo; + bool check; protected: virtual void sendRequest(); public: - UserAddRequest(Application *application, const UserInfo &userInfo0) - : Request(application), userInfo(userInfo0) {} + UserAddRequest(Application *application, const UserInfo &userInfo0, bool checkOnly) + : Request(application), userInfo(userInfo0), check(checkOnly) {} }; class UserUpdateRequest : public Request { @@ -96,6 +97,32 @@ class NetworkUserBackend : public UserDBBackend { : Request(application), uid(uid0), userInfo(userInfo0) {} }; + class GroupAddRequest : public Request { + private: + GroupInfo groupInfo; + bool check; + + protected: + virtual void sendRequest(); + + public: + GroupAddRequest(Application *application, const GroupInfo &groupInfo0, bool checkOnly) + : Request(application), groupInfo(groupInfo0), check(checkOnly) {} + }; + + class GroupUpdateRequest : public Request { + private: + unsigned long gid; + GroupInfo groupInfo; + + protected: + virtual void sendRequest(); + + public: + GroupUpdateRequest(Application *application, unsigned long gid0, const GroupInfo &groupInfo0) + : Request(application), gid(gid0), groupInfo(groupInfo0) {} + }; + class UserGroupRequest : public Request { private: std::string type; @@ -130,10 +157,16 @@ class NetworkUserBackend : public UserDBBackend { //virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); + virtual void checkUserInfo(const UserInfo &userInfo) throw(Core::Exception); virtual void addUser(const UserInfo &userInfo) throw(Core::Exception); virtual void updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception); virtual void deleteUser(unsigned long uid) throw(Core::Exception); + virtual void checkGroupInfo(const GroupInfo &groupInfo) throw(Core::Exception); + virtual void addGroup(const GroupInfo &groupInfo) throw(Core::Exception); + virtual void updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception); + virtual void deleteGroup(unsigned long gid) throw(Core::Exception); + virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); diff --git a/src/Common/UserCache.h b/src/Common/UserCache.h index ff70520..1912caa 100644 --- a/src/Common/UserCache.h +++ b/src/Common/UserCache.h @@ -74,6 +74,11 @@ class UserCache : public UserDBBackend, private boost::noncopyable { backend->setPassword(uid, password); } + + virtual void checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) { + backend->checkUserInfo(userInfo); + } + virtual void addUser(const UserInfo &userInfo) throw(Core::Exception) { backend->addUser(userInfo); } @@ -86,6 +91,11 @@ class UserCache : public UserDBBackend, private boost::noncopyable { backend->deleteUser(uid); } + + virtual void checkGroupInfo(const GroupInfo &groupInfo) throw(Core::Exception) { + backend->checkGroupInfo(groupInfo); + } + virtual void addGroup(const GroupInfo &groupInfo) throw(Core::Exception) { backend->addGroup(groupInfo); } @@ -98,6 +108,7 @@ class UserCache : public UserDBBackend, private boost::noncopyable { backend->deleteGroup(gid); } + virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) { backend->addUserToGroup(uid, gid); } diff --git a/src/Common/UserConfigBackend.h b/src/Common/UserConfigBackend.h index 5055599..0c1f146 100644 --- a/src/Common/UserConfigBackend.h +++ b/src/Common/UserConfigBackend.h @@ -34,10 +34,14 @@ class UserConfigBackend { protected: friend class UserManager; + virtual void checkUserInfo(const UserInfo& /*userInfo*/) throw(Core::Exception) {} + virtual void addUser(const UserInfo& /*userInfo*/) throw(Core::Exception) {} virtual void updateUser(const UserInfo& /*oldUserInfo*/, const UserInfo& /*userInfo*/) throw(Core::Exception) {} virtual void deleteUser(const UserInfo& /*userInfo*/) throw(Core::Exception) {} + virtual void checkGroupInfo(const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} + virtual void addGroup(const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} virtual void updateGroup(const GroupInfo& /*oldGroupInfo*/, const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} virtual void deleteGroup(const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} diff --git a/src/Common/UserDBBackend.h b/src/Common/UserDBBackend.h index bed4c83..4a33f3a 100644 --- a/src/Common/UserDBBackend.h +++ b/src/Common/UserDBBackend.h @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef MAD_SERVER_USERDBBACKEND_H_ -#define MAD_SERVER_USERDBBACKEND_H_ +#ifndef MAD_COMMON_USERDBBACKEND_H_ +#define MAD_COMMON_USERDBBACKEND_H_ #include @@ -90,6 +90,8 @@ class UserDBBackend { } + virtual void checkUserInfo(const UserInfo& /*userInfo*/) throw(Core::Exception) {} + virtual void addUser(const UserInfo& /*userInfo*/) throw(Core::Exception) { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } @@ -103,6 +105,8 @@ class UserDBBackend { } + virtual void checkGroupInfo(const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} + virtual void addGroup(const GroupInfo& /*groupInfo*/) throw(Core::Exception) { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } @@ -132,4 +136,4 @@ class UserDBBackend { } } -#endif /* MAD_SERVER_USERDBBACKEND_H_ */ +#endif /* MAD_COMMON_USERDBBACKEND_H_ */ diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index 37cee6c..7f50f28 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -137,7 +137,22 @@ void UserManager::setPassword(unsigned long /*uid*/, const std::string& /*passwo throw Core::Exception(Core::Exception::NOT_AVAILABLE); } +void UserManager::checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) { + boost::shared_lock lock(mutex); + + if(!dbBackend) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + dbBackend->checkUserInfo(userInfo); + + for(std::set >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + (*configBackend)->checkUserInfo(userInfo); + } +} + void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) { + checkUserInfo(userInfo); + boost::lock_guard lock(mutex); if(!dbBackend) @@ -156,6 +171,8 @@ void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) { } void UserManager::updateUser(unsigned long uid, const UserInfo &userInfo) throw(Core::Exception) { + checkUserInfo(userInfo); + boost::lock_guard lock(mutex); if(!dbBackend) @@ -199,7 +216,23 @@ void UserManager::deleteUser(unsigned long uid) throw(Core::Exception) { } } + +void UserManager::checkGroupInfo(const GroupInfo &groupInfo) throw(Core::Exception) { + boost::shared_lock lock(mutex); + + if(!dbBackend) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + dbBackend->checkGroupInfo(groupInfo); + + for(std::set >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + (*configBackend)->checkGroupInfo(groupInfo); + } +} + void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) { + checkGroupInfo(groupInfo); + boost::lock_guard lock(mutex); if(!dbBackend) @@ -218,6 +251,8 @@ void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) { } void UserManager::updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception) { + checkGroupInfo(groupInfo); + boost::lock_guard lock(mutex); if(!dbBackend) diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h index 5cf14db..5eece35 100644 --- a/src/Common/UserManager.h +++ b/src/Common/UserManager.h @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef MAD_SERVER_USERMANAGER_H_ -#define MAD_SERVER_USERMANAGER_H_ +#ifndef MAD_COMMON_USERMANAGER_H_ +#define MAD_COMMON_USERMANAGER_H_ #include "UserInfo.h" #include "GroupInfo.h" @@ -110,10 +110,12 @@ class UserManager : private boost::noncopyable { void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); + void checkUserInfo(const UserInfo &userInfo) throw(Core::Exception); void addUser(const UserInfo &userInfo) throw(Core::Exception); void updateUser(unsigned long uid, const UserInfo &userInfo) throw(Core::Exception); void deleteUser(unsigned long uid) throw(Core::Exception); + void checkGroupInfo(const GroupInfo &groupInfo) throw(Core::Exception); void addGroup(const GroupInfo &groupInfo) throw(Core::Exception); void updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception); void deleteGroup(unsigned long gid) throw(Core::Exception); @@ -125,4 +127,4 @@ class UserManager : private boost::noncopyable { } } -#endif /* MAD_SERVER_USERMANAGER_H_ */ +#endif /* MAD_COMMON_USERMANAGER_H_ */ -- cgit v1.2.3