otsdaq  v2_04_02
CorePropertySupervisorBase.h
1 #ifndef _ots_CorePropertySupervisorBase_h_
2 #define _ots_CorePropertySupervisorBase_h_
3 
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 #include "otsdaq/ConfigurationInterface/ConfigurationTree.h"
6 #include "otsdaq/Macros/CoutMacros.h"
7 #include "otsdaq/MessageFacility/MessageFacility.h"
8 #include "otsdaq/SupervisorInfo/AllSupervisorInfo.h"
9 #include "otsdaq/TableCore/TableGroupKey.h"
10 #include "otsdaq/TablePlugins/XDAQContextTable.h"
11 
12 #include "otsdaq/WebUsersUtilities/WebUsers.h" //for WebUsers::RequestUserInfo
13 
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
16 #include <xdaq/Application.h>
17 #pragma GCC diagnostic pop
18 
19 namespace ots
20 {
21 // clang-format off
22 
23 // CorePropertySupervisorBase
24 // This class provides supervisor property get and set functionality. It has member
25 // variables generally useful to the configuration of client supervisors.
27 {
28  friend class GatewaySupervisor; // for access to indicateOtsAlive()
29 
30  public:
31  CorePropertySupervisorBase(xdaq::Application* application);
32  virtual ~CorePropertySupervisorBase(void);
33 
34  AllSupervisorInfo allSupervisorInfo_;
35  ConfigurationManager* theConfigurationManager_;
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
43  // access:
44  static void extractPermissionsMapFromString (const std::string& permissionsString, std::map<std::string, WebUsers::permissionLevel_t>& permissionsMap);
45  static bool doPermissionsGrantAccess (std::map<std::string, WebUsers::permissionLevel_t>& permissionLevelsMap, std::map<std::string, WebUsers::permissionLevel_t>& permissionThresholdsMap);
46 
47  ConfigurationTree getContextTreeNode (void) const
48  {
49  return theConfigurationManager_->getNode(
50  theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName());
51  }
52  ConfigurationTree getSupervisorTableNode (void) const
53  {
54  return getContextTreeNode().getNode(supervisorConfigurationPath_);
55  }
56 
57  const std::string& getContextUID (void) const { return supervisorContextUID_; }
58  const std::string& getSupervisorUID (void) const { return supervisorApplicationUID_; }
59  const std::string& getSupervisorConfigurationPath (void) const
60  {
61  return supervisorConfigurationPath_;
62  }
63 
64  protected:
65  const std::string supervisorClass_;
66  const std::string supervisorClassNoNamespace_;
67 
68  private:
69  static void indicateOtsAlive (const CorePropertySupervisorBase* properties = 0);
70 
71  std::string supervisorContextUID_;
72  std::string supervisorApplicationUID_;
73  std::string supervisorConfigurationPath_;
74 
75  protected:
76  // Supervisor Property names
77  // to access, use CorePropertySupervisorBase::getSupervisorProperty and
78  // CorePropertySupervisorBase::setSupervisorProperty
79  static const struct SupervisorProperties
80  {
82  : allSetNames_({&CheckUserLockRequestTypes,
83  &RequireUserLockRequestTypes,
84  &AutomatedRequestTypes,
85  &AllowNoLoginRequestTypes,
86  &RequireSecurityRequestTypes,
87  &NoXmlWhiteSpaceRequestTypes,
88  &NonXMLRequestTypes})
89  {
90  }
91 
92  const std::string UserPermissionsThreshold = "UserPermissionsThreshold";
93  const std::string UserGroupsAllowed = "UserGroupsAllowed";
94  const std::string UserGroupsDisallowed = "UserGroupsDisallowed";
95 
96  const std::string CheckUserLockRequestTypes = "CheckUserLockRequestTypes";
97  const std::string RequireUserLockRequestTypes = "RequireUserLockRequestTypes";
98  const std::string AutomatedRequestTypes = "AutomatedRequestTypes";
99  const std::string AllowNoLoginRequestTypes = "AllowNoLoginRequestTypes";
100  const std::string RequireSecurityRequestTypes = "RequireSecurityRequestTypes";
101 
102  const std::string NoXmlWhiteSpaceRequestTypes = "NoXmlWhiteSpaceRequestTypes";
103  const std::string NonXMLRequestTypes = "NonXMLRequestTypes";
104 
105  const std::set<const std::string*> allSetNames_;
106  } SUPERVISOR_PROPERTIES;
107 
108  private:
109  // property private members
110  void checkSupervisorPropertySetup (void);
111  volatile bool propertiesAreSetup_;
112 
113  // for public access to property map,..
114  // use CorePropertySupervisorBase::getSupervisorProperty and
115  // CorePropertySupervisorBase::setSupervisorProperty
116  std::map<std::string, std::string> propertyMap_;
117  struct CoreSupervisorPropertyStruct
118  {
119  CoreSupervisorPropertyStruct()
120  : allSets_({&CheckUserLockRequestTypes,
121  &RequireUserLockRequestTypes,
122  &AutomatedRequestTypes,
123  &AllowNoLoginRequestTypes,
124  &RequireSecurityRequestTypes,
125  &NoXmlWhiteSpaceRequestTypes,
126  &NonXMLRequestTypes})
127  {
128  }
129 
130  std::map<std::string, WebUsers::permissionLevel_t> UserPermissionsThreshold;
131  std::map<std::string, std::string> UserGroupsAllowed;
132  std::map<std::string, std::string> UserGroupsDisallowed;
133 
134  std::set<std::string> CheckUserLockRequestTypes;
135  std::set<std::string> RequireUserLockRequestTypes;
136  std::set<std::string> AutomatedRequestTypes;
137  std::set<std::string> AllowNoLoginRequestTypes;
138  std::set<std::string> RequireSecurityRequestTypes;
139 
140  std::set<std::string> NoXmlWhiteSpaceRequestTypes;
141  std::set<std::string> NonXMLRequestTypes;
142 
143  std::set<std::set<std::string>*> allSets_;
144  } propertyStruct_;
145 
146  public:
147  void resetPropertiesAreSetup (void)
148  {
149  propertiesAreSetup_ = false;
150  } // forces reload of properties from configuration
151  ConfigurationTree getSupervisorTreeNode(void);
152 
153  void loadUserSupervisorProperties (void);
154  template<class T>
155  void setSupervisorProperty (
156  const std::string& propertyName, const T& propertyValue)
157  {
158  std::stringstream ss;
159  ss << propertyValue;
160  setSupervisorProperty(propertyName, ss.str());
161  } //end setSupervisorProperty()
162  void setSupervisorProperty (const std::string& propertyName,
163  const std::string& propertyValue);
164  template<class T>
165  void addSupervisorProperty (
166  const std::string& propertyName, const T& propertyValue)
167  {
168  // prepend new values.. since map/set extraction takes the first value encountered
169  std::stringstream ss;
170  ss << propertyValue << " | " << getSupervisorProperty(propertyName);
171  setSupervisorProperty(propertyName, ss.str());
172  } //end addSupervisorProperty()
173  void addSupervisorProperty (const std::string& propertyName, const std::string& propertyValue);
174  template<class T>
175  T getSupervisorProperty (
176  const std::string& propertyName)
177  {
178  // check if need to setup properties
179  checkSupervisorPropertySetup();
180 
181  auto it = propertyMap_.find(propertyName);
182  if(it == propertyMap_.end())
183  {
184  __SS__ << "Could not find property named " << propertyName << __E__;
185  __SS_THROW__;
186  }
187  return StringMacros::validateValueForDefaultStringDataType<T>(it->second);
188  } //end getSupervisorProperty()
189  template<class T>
190  T getSupervisorProperty (
191  const std::string& propertyName, const T& defaultValue)
192  {
193  // check if need to setup properties
194  checkSupervisorPropertySetup();
195 
196  auto it = propertyMap_.find(propertyName);
197  if(it == propertyMap_.end())
198  {
199  //not found, so returning default value
200  return defaultValue;
201  }
202  return StringMacros::validateValueForDefaultStringDataType<T>(it->second);
203  } //end getSupervisorProperty()
204  std::string getSupervisorProperty (const std::string& propertyName);
205  std::string getSupervisorProperty (const std::string& propertyName, const std::string& defaultValue);
206  WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold (const std::string& requestType);
207 };
208 
209 // clang-format on
210 
211 } // namespace ots
212 
213 #endif