00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(ms_security_INCLUDED_)
00022 #define ms_security_INCLUDED_
00023
00024
00025
00026 #include <string>
00027 #include <set>
00028 #include <vector>
00029 #include <map>
00030
00031
00032 #ifdef _WIN32
00033 #include <io.h>
00034 #endif
00035
00036 #include <time.h>
00037
00038 namespace matrix_science {
00039 class ms_security_options;
00040 class ms_security_task;
00041 class ms_security_tasks;
00042
00043 #ifndef SWIG
00044 class ms_userSortByID
00045 {
00046 public:
00047 bool operator() (const ms_user * t1, const ms_user * t2) const
00048 {
00049 return (t1->getID() < t2->getID());
00050 }
00051 };
00052
00053 class ms_userSortByLoginName
00054 {
00055 public:
00056 bool operator() (const ms_user * t1, const ms_user * t2) const
00057 {
00058 return (t1->getName() < t2->getName());
00059 }
00060 };
00061
00062 class ms_userSortByFullName
00063 {
00064 public:
00065 bool operator() (const ms_user * t1, const ms_user * t2) const
00066 {
00067 return (t1->getFullName() < t2->getFullName());
00068 }
00069 };
00070
00071 class ms_groupSortByID
00072 {
00073 public:
00074 bool operator() (const ms_group * t1, const ms_group * t2) const
00075 {
00076 return (t1->getID() < t2->getID());
00077 }
00078 };
00079
00080 #endif
00081
00086
00087
00093 class MS_MASCOTRESFILE_API ms_security : public ms_errors
00094 {
00095
00096 public:
00098 ms_security();
00099 ~ms_security();
00100
00101 public:
00102
00104 enum USERID_SORTBY
00105 {
00106 USERID_SORTBY_ID = 1,
00107 USERID_SORTBY_LOGINNAME = 2,
00108 USERID_SORTBY_FULLNAME = 3
00109 };
00110
00112 bool addNewUser(const std::string sessionID,
00113 const int userID,
00114 const std::string userName,
00115 const std::string password,
00116 const time_t passwordExpiry,
00117 const std::string fullName,
00118 const std::string emailAddress,
00119 const ms_user::usertype userType,
00120 const bool enabled);
00121
00123 ms_user getUser(const std::string userName) const;
00124
00126 ms_user getUserFromID(const int userID) const;
00127
00129 bool isUserExists(const int userID) const;
00130
00132 std::vector<int> sortUsers(std::vector<ms_user*> & vecUsers, const USERID_SORTBY sortby) const;
00133
00135 std::vector<int> getAllUserIDs(const USERID_SORTBY sortby = USERID_SORTBY_ID) const;
00136
00138 bool deleteUser(const std::string sessionID, const std::string userName);
00139
00141 bool updateUser(const std::string sessionID, const ms_user user);
00142
00144 bool updatePassword(const std::string sessionID,
00145 const std::string userName,
00146 const std::string oldPassword,
00147 const std::string newPassword);
00148
00150 std::vector<std::string> getIntegraUsers() const;
00151
00153 bool addNewGroup(const std::string sessionID,
00154 const int groupID,
00155 const std::string groupName);
00156
00158 ms_group getGroup(const std::string groupName) const;
00159
00161 ms_group getGroupFromID(const int groupID) const;
00162
00164 std::vector<int> getAllGroupIDs() const;
00165
00167 bool deleteGroup(const std::string sessionID, const std::string groupName);
00168
00170 bool updateGroup(const std::string sessionID, const ms_group & group);
00171
00173 ms_security_tasks getPermittedTasksForUser(const std::string name) const;
00174
00176 ms_user::customParams_t getAllCustomParamsForUser(const ms_user & user) const;
00177
00179 ms_security_options getMascotSecurityOptions() const;
00180
00182 ms_security_tasks getTasks() const;
00183
00185 bool isTaskExists(const int taskID) const;
00186
00188 bool createDefaults(const std::string sessionID = "");
00189
00191 bool updateAllSessionFiles(bool deleteOnly = false);
00192
00193 protected:
00194 bool loadFromFile();
00195 bool saveToFile();
00196
00197 private:
00198
00199 ms_security(const ms_security & src);
00200 ms_security& operator=(const ms_security & right);
00201
00202 typedef std::set<ms_user *, ms_userSortByID> userlist_t;
00203 typedef std::set<ms_group *, ms_groupSortByID> grouplist_t;
00204
00205 const char * invalidChars_;
00206
00207 userlist_t users_;
00208 grouplist_t groups_;
00209 ms_security_tasks * tasks_;
00210 ms_security_options options_;
00211 int nextFreeGroupID_;
00212 int nextFreeUserID_;
00213
00214 void removeAllUsersFromMemory();
00215 void removeAllGroupsFromMemory();
00216 bool doUpdateUser(const ms_user user);
00217
00218 };
00220 }
00221 #endif // !defined(ms_security_INCLUDED_)