summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/NetworkUserBackend.cpp87
-rw-r--r--src/Common/Backends/NetworkUserBackend.h37
-rw-r--r--src/Common/UserCache.h11
-rw-r--r--src/Common/UserConfigBackend.h4
-rw-r--r--src/Common/UserDBBackend.h10
-rw-r--r--src/Common/UserManager.cpp35
-rw-r--r--src/Common/UserManager.h8
7 files changed, 182 insertions, 10 deletions
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<const std::multimap<unsigned long, unsigned long> > NetworkUse
}*/
+void NetworkUserBackend::checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::shared_ptr<UserAddRequest> request(new UserAddRequest(application, userInfo, true));
+ 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;
+}
+
void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) {
application->getThreadManager()->detach();
- boost::shared_ptr<UserAddRequest> request(new UserAddRequest(application, userInfo));
+ boost::shared_ptr<UserAddRequest> 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<GroupAddRequest> request(new GroupAddRequest(application, groupInfo, true));
+ 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;
+}
+
+void NetworkUserBackend::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::shared_ptr<GroupAddRequest> request(new GroupAddRequest(application, groupInfo, false));
+ 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;
+}
+
+void NetworkUserBackend::updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::shared_ptr<GroupUpdateRequest> request(new GroupUpdateRequest(application, gid, groupInfo));
+ 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;
+}
+
+void NetworkUserBackend::deleteGroup(unsigned long gid) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "DeleteGroup", "gid", gid));
+ 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;
+}
+
+
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 <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_SERVER_USERDBBACKEND_H_
-#define MAD_SERVER_USERDBBACKEND_H_
+#ifndef MAD_COMMON_USERDBBACKEND_H_
+#define MAD_COMMON_USERDBBACKEND_H_
#include <Core/Exception.h>
@@ -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<boost::shared_mutex> lock(mutex);
+
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ dbBackend->checkUserInfo(userInfo);
+
+ for(std::set<boost::shared_ptr<UserConfigBackend> >::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<boost::shared_mutex> 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<boost::shared_mutex> 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<boost::shared_mutex> lock(mutex);
+
+ if(!dbBackend)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ dbBackend->checkGroupInfo(groupInfo);
+
+ for(std::set<boost::shared_ptr<UserConfigBackend> >::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<boost::shared_mutex> 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<boost::shared_mutex> 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 <http://www.gnu.org/licenses/>.
*/
-#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_ */