1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF)                              */
3 /* (C) Copyright IBM Corp. 2001                                              */
4 /*                                                                           */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0.    */
6 /*****************************************************************************/
7 
8 #ifndef STAF_TrustManager
9 #define STAF_TrustManager
10 
11 #include <map>
12 #include "STAF.h"
13 #include "STAFString.h"
14 #include "STAFUtil.h"
15 #include "STAFRefPtr.h"
16 #include "STAFMutexSem.h"
17 #include "STAFFileSystem.h"
18 
19 
20 class STAFTrustManager
21 {
22 public:
23 
24     // Public types
25 
26     struct TrustData
27     {
28         enum TrustMatchType
29         {
30             kTrustMatchExact       = 0,
31             kTrustMatchGroupExact  = 1,
32             kTrustMatchEntityExact = 2,
33             kTrustMatchWildcard    = 3,
34             kTrustMatchNoMatch     = 4
35         };
36 
TrustDataTrustData37         TrustData() { /* Do Nothing */ }
38 
39         TrustData(const STAFString &theGroup, const STAFString &theEntity,
40                   unsigned int theTrustLevel);
41 
42         STAFString group;
43         STAFString entity;
44         unsigned int trustLevel;
45         TrustMatchType matchType;
46     };
47 
48     typedef std::map<STAFString, TrustData> TrustMap;
49 
50     STAFTrustManager(unsigned int maxTrustLevel,
51                      unsigned int defaultTrustLevel = 3)
fMaxTrustLevel(maxTrustLevel)52         : fMaxTrustLevel(maxTrustLevel), fDefaultTrustLevel(defaultTrustLevel)
53     { /* Do Nothing */ }
54 
55     unsigned int getTrustLevel(const STAFString &theInterface,
56                                const STAFString &logicalID,
57                                const STAFString &physicalID,
58                                const STAFString &authenticator,
59                                const STAFString &userID);
60     unsigned int getTrustLevel(const STAFString &machine,
61                                const STAFString &user);
62     unsigned int getTrustLevel(const STAFString &machine);
63 
64     STAFRC_t setMachineTrusteeLevel(const STAFString &machine,
65                                     unsigned int trustLevel);
66     STAFRC_t deleteMachineTrustee(const STAFString &machine);
67     TrustMap getMachineTrustMapCopy();
68 
69     STAFRC_t setUserTrusteeLevel(STAFString user,
70                                  unsigned int trustLevel);
71     STAFRC_t deleteUserTrustee(STAFString user);
72     TrustMap getUserTrustMapCopy();
73 
74     unsigned int getDefaultTrusteeLevel();
75     STAFRC_t setDefaultTrusteeLevel(unsigned int trustLevel);
76 
77     unsigned int getMaxTrustLevel();
78 
79 private:
80 
81     // Don't allow copy construction or assignment
82     STAFTrustManager(const STAFTrustManager &);
83     STAFTrustManager &operator=(const STAFTrustManager &);
84 
85     void splitSpecification(const STAFString &source,
86                             const STAFString &defaultGroup,
87                             STAFString &group,
88                             STAFString &entity);
89 
90     unsigned int fMaxTrustLevel;
91     unsigned int fDefaultTrustLevel;
92     STAFMutexSem fTrustDataSem;
93     TrustMap fMachineTrustMap;
94     TrustMap fUserTrustMap;
95 };
96 
97 #endif
98