Matrix Science header

ms_security.hpp

00001 /*
00002 ##############################################################################
00003 # file: ms_security.hpp                                                      #
00004 # 'msparser' toolkit                                                         #
00005 # Encapsulates Mascot security as used in authentication                     #
00006 ##############################################################################
00007 # COPYRIGHT NOTICE                                                           #
00008 # Copyright 1998-2004 Matrix Science Limited  All Rights Reserved.           #
00009 #                                                                            #
00010 ##############################################################################
00011 #    $Archive:: /MowseBranches/ms_mascotresfile_1.2/include/ms_mascotresfi $ #
00012 #     $Author: francoisr $ #
00013 #       $Date: 2016/05/18 17:08:14 $ #
00014 #   $Revision: 1.19 $ #
00015 # $NoKeywords::                                                            $ #
00016 ##############################################################################
00017 */
00018 
00019 
00020 
00021 #if !defined(ms_security_INCLUDED_)
00022 #define ms_security_INCLUDED_
00023 
00024 #ifdef _WIN32
00025 #pragma warning(disable:4251)   // Don't want all classes to be exported
00026 #pragma warning(disable:4786)   // Debug symbols too long
00027 #   ifndef _MATRIX_USE_STATIC_LIB
00028 #       ifdef MS_MASCOTRESFILE_EXPORTS
00029 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00030 #       else
00031 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00032 #       endif
00033 #   else
00034 #       define MS_MASCOTRESFILE_API
00035 #   endif
00036 #else
00037 #   define MS_MASCOTRESFILE_API
00038 #endif
00039 
00040 // for the sake of #include <string>
00041 #ifdef __ALPHA_UNIX__
00042 #include <ctype.h>
00043 #endif
00044 
00045 // Includes from the standard template library
00046 #include <string>
00047 #include <set>
00048 #include <vector>
00049 #include <map>
00050 
00051 
00052 #ifdef _WIN32
00053 #include <io.h>
00054 #else
00055 #endif
00056 
00057 #include <time.h>
00058 
00059 namespace matrix_science {
00060     class ms_security_options;
00061     class ms_security_task;
00062     class ms_security_tasks;
00063 
00064 #ifndef SWIG
00065     class ms_userSortByID
00066     {
00067     public:
00068         bool operator() (const ms_user * t1, const ms_user * t2) const
00069         {
00070             return (t1->getID() < t2->getID());
00071         }
00072     };
00073 
00074     class ms_userSortByLoginName
00075     {
00076     public:
00077         bool operator() (const ms_user * t1, const ms_user * t2) const
00078         {
00079             return (t1->getName() < t2->getName());
00080         }
00081     };
00082 
00083     class ms_userSortByFullName
00084     {
00085     public:
00086         bool operator() (const ms_user * t1, const ms_user * t2) const
00087         {
00088             return (t1->getFullName() < t2->getFullName());
00089         }
00090     };
00091 
00092     class ms_groupSortByID
00093     {
00094     public:
00095         bool operator() (const ms_group * t1, const ms_group * t2) const
00096         {
00097             return (t1->getID() < t2->getID());
00098         }
00099     };
00100 
00101 #endif
00102 
00107 
00108 
00114     class MS_MASCOTRESFILE_API ms_security : public ms_errors
00115     {
00116 
00117     public:
00119         ms_security();
00120         ~ms_security();
00121 
00122     public:
00123 
00125         enum USERID_SORTBY
00126         {
00127             USERID_SORTBY_ID         = 1,  
00128             USERID_SORTBY_LOGINNAME  = 2,  
00129             USERID_SORTBY_FULLNAME   = 3  
00130         };
00131 
00133         bool addNewUser(const std::string       sessionID,
00134                         const int               userID,
00135                         const std::string       userName,
00136                         const std::string       password,
00137                         const time_t            passwordExpiry,
00138                         const std::string       fullName,
00139                         const std::string       emailAddress,
00140                         const ms_user::usertype userType,
00141                         const bool              enabled);
00142 
00144         ms_user getUser(const std::string userName) const;
00145 
00147         ms_user getUserFromID(const int userID) const;
00148 
00150         bool isUserExists(const int userID) const;
00151 
00153         std::vector<int> sortUsers(std::vector<ms_user*> & vecUsers, const USERID_SORTBY sortby) const;
00154 
00156         std::vector<int> getAllUserIDs(const USERID_SORTBY sortby = USERID_SORTBY_ID) const;
00157 
00159         bool deleteUser(const std::string sessionID, const std::string userName);
00160 
00162         bool updateUser(const std::string sessionID, const ms_user user);
00163 
00165         bool updatePassword(const std::string sessionID, 
00166                             const std::string userName,
00167                             const std::string oldPassword,
00168                             const std::string newPassword);
00169 
00171         std::vector<std::string> getIntegraUsers() const;
00172 
00174         bool addNewGroup(const std::string sessionID,
00175                          const int groupID,
00176                          const std::string groupName);
00177 
00179         ms_group getGroup(const std::string groupName) const;
00180 
00182         ms_group getGroupFromID(const int groupID) const;
00183 
00185         std::vector<int> getAllGroupIDs() const;
00186 
00188         bool deleteGroup(const std::string sessionID, const std::string groupName);
00189 
00191         bool updateGroup(const std::string sessionID, const ms_group & group);
00192 
00194         ms_security_tasks getPermittedTasksForUser(const std::string name) const;
00195 
00197         ms_user::customParams_t getAllCustomParamsForUser(const ms_user & user) const;
00198 
00200         ms_security_options getMascotSecurityOptions() const;
00201 
00203         ms_security_tasks getTasks() const;
00204 
00206         bool isTaskExists(const int taskID) const;
00207 
00209         bool createDefaults(const std::string sessionID = "");
00210 
00212         bool updateAllSessionFiles(bool deleteOnly = false);
00213 
00214     protected:
00215         bool loadFromFile();
00216         bool saveToFile();
00217 
00218     private:
00219         //do not copy this class
00220         ms_security(const ms_security & src);
00221         ms_security& operator=(const ms_security & right);
00222 
00223         typedef std::set<ms_user  *, ms_userSortByID>  userlist_t;
00224         typedef std::set<ms_group *, ms_groupSortByID> grouplist_t;
00225 
00226         const char * invalidChars_;
00227 
00228         userlist_t users_;
00229         grouplist_t groups_;
00230         ms_security_tasks * tasks_;
00231         ms_security_options options_;
00232         int nextFreeGroupID_;
00233         int nextFreeUserID_;
00234 
00235         void removeAllUsersFromMemory();
00236         void removeAllGroupsFromMemory();
00237         bool doUpdateUser(const ms_user user);
00238 
00239     }; // end of security_group
00241 }
00242 #endif // !defined(ms_security_INCLUDED_)
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51