diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-08-16 03:01:12 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-08-16 03:01:12 +0200 |
commit | b6f7d36a544a7a8c18c815ef4158cf684108d06d (patch) | |
tree | 417e12f98f5b2c6d03bd740999532e61d60a664a /src/Common | |
parent | c1cb92bc30256171bfafb22cf8512142afee97cf (diff) | |
download | mad-b6f7d36a544a7a8c18c815ef4158cf684108d06d.tar mad-b6f7d36a544a7a8c18c815ef4158cf684108d06d.zip |
Passwörter können gesetzt werden
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Backends/NetworkUserBackend.cpp | 27 | ||||
-rw-r--r-- | src/Common/Backends/NetworkUserBackend.h | 17 | ||||
-rw-r--r-- | src/Common/UserCache.h | 10 | ||||
-rw-r--r-- | src/Common/UserConfigBackend.h | 22 | ||||
-rw-r--r-- | src/Common/UserDBBackend.h | 10 | ||||
-rw-r--r-- | src/Common/UserManager.cpp | 43 | ||||
-rw-r--r-- | src/Common/UserManager.h | 4 |
7 files changed, 101 insertions, 32 deletions
diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index da964e7..00bd378 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -115,6 +115,15 @@ void NetworkUserBackend::UserGroupRequest::sendRequest() { sendPacket(packet); } +void NetworkUserBackend::PasswordRequest::sendRequest() { + XmlPacket packet; + packet.setType("SetPassword"); + packet.set("uid", uid); + packet.set("password", password); + + sendPacket(packet); +} + boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); @@ -397,11 +406,6 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUse } -/*void NetworkUserBackend::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { - -}*/ - - void NetworkUserBackend::checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) { application->getThreadManager()->detach(); @@ -524,6 +528,19 @@ void NetworkUserBackend::deleteUserFromGroup(unsigned long uid, unsigned long gi throw result.second; } + +void NetworkUserBackend::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::shared_ptr<PasswordRequest> request(new PasswordRequest(application, uid, password)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); + + std::pair<boost::shared_ptr<const XmlPacket>, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} + } } } diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h index a3fa1a6..1ab0b58 100644 --- a/src/Common/Backends/NetworkUserBackend.h +++ b/src/Common/Backends/NetworkUserBackend.h @@ -137,6 +137,19 @@ class NetworkUserBackend : public UserDBBackend { : Request(application), type(type0), uid(uid0), gid(gid0) {} }; + class PasswordRequest : public Request { + private: + unsigned long uid; + std::string password; + + protected: + virtual void sendRequest(); + + public: + PasswordRequest(Application *application, unsigned long uid0, const std::string &password0) + : Request(application), uid(uid0), password(password0) {} + }; + static const std::string name; Application *application; @@ -155,8 +168,6 @@ class NetworkUserBackend : public UserDBBackend { virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); - //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); @@ -170,6 +181,8 @@ class NetworkUserBackend : public UserDBBackend { virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); + virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); + public: NetworkUserBackend(Application *application0, Connection *connection0) : application(application0), connection(connection0) {} diff --git a/src/Common/UserCache.h b/src/Common/UserCache.h index 1912caa..bec3328 100644 --- a/src/Common/UserCache.h +++ b/src/Common/UserCache.h @@ -70,11 +70,6 @@ class UserCache : public UserDBBackend, private boost::noncopyable { virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { - backend->setPassword(uid, password); - } - - virtual void checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) { backend->checkUserInfo(userInfo); } @@ -117,6 +112,11 @@ class UserCache : public UserDBBackend, private boost::noncopyable { backend->deleteUserFromGroup(uid, gid); } + + virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { + backend->setPassword(uid, password); + } + UserCache(Application *application0, boost::shared_ptr<UserDBBackend> backend0) : application(application0), backend(backend0), userTime(boost::posix_time::not_a_date_time), groupTime(boost::posix_time::not_a_date_time), userGroupTime(boost::posix_time::not_a_date_time) {} diff --git a/src/Common/UserConfigBackend.h b/src/Common/UserConfigBackend.h index 0c1f146..94550eb 100644 --- a/src/Common/UserConfigBackend.h +++ b/src/Common/UserConfigBackend.h @@ -36,18 +36,22 @@ class UserConfigBackend { 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 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 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) {} + 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) {} - virtual void addUserToGroup(const UserInfo& /*userInfo*/, const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} - virtual void deleteUserFromGroup(const UserInfo& /*userInfo*/, const GroupInfo& /*groupInfo*/) throw(Core::Exception) {} + virtual void addUserToGroup(const UserInfo &/*userInfo*/, const GroupInfo &/*groupInfo*/) throw(Core::Exception) {} + virtual void deleteUserFromGroup(const UserInfo &/*userInfo*/, const GroupInfo &/*groupInfo*/) throw(Core::Exception) {} + + virtual void setPassword(const Common::UserInfo &/*userInfo*/, const std::string &/*password*/) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } }; } diff --git a/src/Common/UserDBBackend.h b/src/Common/UserDBBackend.h index 4a33f3a..664739c 100644 --- a/src/Common/UserDBBackend.h +++ b/src/Common/UserDBBackend.h @@ -85,11 +85,6 @@ class UserDBBackend { } - virtual void setPassword(unsigned long /*uid*/, const std::string& /*password*/) throw(Core::Exception) { - throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); - } - - virtual void checkUserInfo(const UserInfo& /*userInfo*/) throw(Core::Exception) {} virtual void addUser(const UserInfo& /*userInfo*/) throw(Core::Exception) { @@ -127,6 +122,11 @@ class UserDBBackend { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } + + virtual void setPassword(unsigned long /*uid*/, const std::string& /*password*/) throw(Core::Exception) { + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + } + public: virtual ~UserDBBackend() {} diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index bb4d205..d04a644 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -203,10 +203,6 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > UserManage return dbBackend->getFullUserGroupList(timestamp); } -void UserManager::setPassword(unsigned long /*uid*/, const std::string& /*password*/) throw(Core::Exception) { - throw Core::Exception(Core::Exception::NOT_AVAILABLE); -} - void UserManager::checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); @@ -422,5 +418,44 @@ void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) thro } } +void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { + boost::lock_guard<boost::shared_mutex> lock(mutex); + + if(!dbBackend) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + boost::shared_ptr<const UserInfo> userInfo = dbBackend->getUserInfo(uid, 0); + if(!userInfo) + throw Core::Exception(Core::Exception::NOT_FOUND); + + bool ok = false; + Core::Exception exception; + + try { + dbBackend->setPassword(uid, password); + ok = true; + } + catch(Core::Exception e) { + exception = e; + + if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + + for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { + try { + (*configBackend)->setPassword(*userInfo, password); + ok = true; + } + catch(Core::Exception e) { + if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror()); + } + } + + if(!ok) + throw exception; +} + } } diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h index c70894a..b966662 100644 --- a/src/Common/UserManager.h +++ b/src/Common/UserManager.h @@ -115,8 +115,6 @@ class UserManager : public Core::Configurable, private boost::noncopyable { boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); - 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); @@ -129,6 +127,8 @@ class UserManager : public Core::Configurable, private boost::noncopyable { void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); + + void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); }; } |