otsdaq  v2_01_00
CorePropertySupervisorBase.h
1 #ifndef _ots_CorePropertySupervisorBase_h_
2 #define _ots_CorePropertySupervisorBase_h_
3 
4 
5 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
6 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
7 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
8 #include "otsdaq-core/ConfigurationInterface/ConfigurationTree.h"
9 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
10 #include "otsdaq-core/MessageFacility/MessageFacility.h"
11 #include "otsdaq-core/Macros/CoutMacros.h"
12 
13 #include "otsdaq-core/WebUsersUtilities/WebUsers.h" //for WebUsers::RequestUserInfo
14 
15 #pragma GCC diagnostic push
16 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
17 #include <xdaq/Application.h>
18 #pragma GCC diagnostic pop
19 
20 
21 
22 
23 namespace ots
24 {
25 
26 //CorePropertySupervisorBase
27 // This class provides supervisor property get and set functionality. It has member variables
28 // generally useful to the configuration of client supervisors.
30 {
31 
32 public:
33  CorePropertySupervisorBase (xdaq::Application* application);
34  virtual ~CorePropertySupervisorBase (void);
35 
36 
37  virtual void setSupervisorPropertyDefaults (void); //override to control supervisor specific defaults
38  virtual void forceSupervisorPropertyValues (void) {;} //override to force supervisor property values (and ignore user settings)
39 
40  void getRequestUserInfo (WebUsers::RequestUserInfo& requestUserInfo);
41 
42  //supervisors should use these two static functions to standardize permissions access:
43  static void extractPermissionsMapFromString (const std::string& permissionsString, std::map<std::string,WebUsers::permissionLevel_t>& permissionsMap);
44  static bool doPermissionsGrantAccess (std::map<std::string,WebUsers::permissionLevel_t>& permissionLevelsMap, std::map<std::string,WebUsers::permissionLevel_t>& permissionThresholdsMap);
45 
46  ConfigurationTree getContextTreeNode (void) const { return theConfigurationManager_->getNode(theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getConfigurationName()); }
47 protected:
48 
49 
50  ConfigurationManager* theConfigurationManager_;
51 
52  std::string supervisorClass_;
53  std::string supervisorClassNoNamespace_;
54 
55  std::string supervisorContextUID_;
56  std::string supervisorApplicationUID_;
57  std::string supervisorConfigurationPath_;
58 
59  AllSupervisorInfo allSupervisorInfo_;
60 
61  //Supervisor Property names
62  // to access, use CorePropertySupervisorBase::getSupervisorProperty and CorePropertySupervisorBase::setSupervisorProperty
63  static const struct SupervisorProperties
64  {
66  : allSetNames_({&CheckUserLockRequestTypes,&RequireUserLockRequestTypes,
67  &AutomatedRequestTypes,&AllowNoLoginRequestTypes,
68  &NoXmlWhiteSpaceRequestTypes,&NonXMLRequestTypes})
69  {}
70 
71  const std::string UserPermissionsThreshold = "UserPermissionsThreshold";
72  const std::string UserGroupsAllowed = "UserGroupsAllowed";
73  const std::string UserGroupsDisallowed = "UserGroupsDisallowed";
74 
75  const std::string CheckUserLockRequestTypes = "CheckUserLockRequestTypes";
76  const std::string RequireUserLockRequestTypes = "RequireUserLockRequestTypes";
77  const std::string AutomatedRequestTypes = "AutomatedRequestTypes";
78  const std::string AllowNoLoginRequestTypes = "AllowNoLoginRequestTypes";
79 
80  const std::string NoXmlWhiteSpaceRequestTypes = "NoXmlWhiteSpaceRequestTypes";
81  const std::string NonXMLRequestTypes = "NonXMLRequestTypes";
82 
83  const std::set<const std::string*> allSetNames_;
84  } SUPERVISOR_PROPERTIES;
85 
86 private:
87  //property private members
88  void checkSupervisorPropertySetup (void);
89  volatile bool propertiesAreSetup_;
90 
91  //for public access to property map,..
92  // use CorePropertySupervisorBase::getSupervisorProperty and CorePropertySupervisorBase::setSupervisorProperty
93  std::map<std::string, std::string> propertyMap_;
94  struct CoreSupervisorPropertyStruct
95  {
96  CoreSupervisorPropertyStruct()
97  : allSets_ ({&CheckUserLockRequestTypes,&RequireUserLockRequestTypes,
98  &AutomatedRequestTypes,&AllowNoLoginRequestTypes,
99  &NoXmlWhiteSpaceRequestTypes,&NonXMLRequestTypes})
100  {}
101 
102  std::map<std::string,WebUsers::permissionLevel_t> UserPermissionsThreshold;
103  std::map<std::string,std::string> UserGroupsAllowed;
104  std::map<std::string,std::string> UserGroupsDisallowed;
105 
106  std::set<std::string> CheckUserLockRequestTypes;
107  std::set<std::string> RequireUserLockRequestTypes;
108  std::set<std::string> AutomatedRequestTypes;
109  std::set<std::string> AllowNoLoginRequestTypes;
110 
111  std::set<std::string> NoXmlWhiteSpaceRequestTypes;
112  std::set<std::string> NonXMLRequestTypes;
113 
114  std::set< std::set<std::string>* > allSets_;
115  } propertyStruct_;
116 
117 public:
118  void resetPropertiesAreSetup (void) { propertiesAreSetup_ = false; } //forces reload of properties from configuration
119  ConfigurationTree getSupervisorTreeNode (void);
120 
121  void loadUserSupervisorProperties (void);
122  template<class T>
123  void setSupervisorProperty (const std::string& propertyName, const T& propertyValue)
124  {
125  std::stringstream ss;
126  ss << propertyValue;
127  setSupervisorProperty(propertyName,ss.str());
128  }
129  void setSupervisorProperty (const std::string& propertyName, const std::string& propertyValue);
130  template<class T>
131  void addSupervisorProperty (const std::string& propertyName, const T& propertyValue)
132  {
133  //prepend new values.. since map/set extraction takes the first value encountered
134  std::stringstream ss;
135  ss << propertyValue << " | " << getSupervisorProperty(propertyName);
136  setSupervisorProperty(propertyName,ss.str());
137  }
138  void addSupervisorProperty (const std::string& propertyName, const std::string& propertyValue);
139  template<class T>
140  T getSupervisorProperty (const std::string& propertyName)
141  {
142  //check if need to setup properties
143  checkSupervisorPropertySetup();
144 
145  auto it = propertyMap_.find(propertyName);
146  if(it == propertyMap_.end())
147  {
148  __SS__ << "Could not find property named " << propertyName << __E__;
149  __SS_THROW__;
150  }
151  return StringMacros::validateValueForDefaultStringDataType<T>(it->second);
152  }
153  std::string getSupervisorProperty(const std::string& propertyName);
154  WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold(const std::string& requestType);
155 
156 };
157 
158 }
159 
160 #endif