otsdaq  v2_05_02_indev
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  XDAQ_CONST_CALL xdaq::ApplicationDescriptor* getGatewaySupervisorDescriptor (void); //will be wizard supervisor in wiz mode
38 
39  virtual void setSupervisorPropertyDefaults (void); // override to control supervisor specific defaults
40  virtual void forceSupervisorPropertyValues (void){;} // override to force supervisor property values (and ignore user settings)
41 
42  void getRequestUserInfo (WebUsers::RequestUserInfo& requestUserInfo);
43 
44  // supervisors should use these two static functions to standardize permissions
45  // access:
46  static void extractPermissionsMapFromString (const std::string& permissionsString, std::map<std::string, WebUsers::permissionLevel_t>& permissionsMap);
47  static bool doPermissionsGrantAccess (std::map<std::string, WebUsers::permissionLevel_t>& permissionLevelsMap, std::map<std::string, WebUsers::permissionLevel_t>& permissionThresholdsMap);
48 
49  ConfigurationTree getContextTreeNode (void) const
50  {
51  return theConfigurationManager_->getNode(
52  theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName());
53  }
54  ConfigurationTree getSupervisorTableNode (void) const
55  {
56  return getContextTreeNode().getNode(supervisorConfigurationPath_);
57  }
58 
59  const std::string& getContextUID (void) const { return supervisorContextUID_; }
60  const std::string& getSupervisorUID (void) const { return supervisorApplicationUID_; }
61  const std::string& getSupervisorConfigurationPath (void) const
62  {
63  return supervisorConfigurationPath_;
64  }
65 
66  protected:
67  const std::string supervisorClass_;
68  const std::string supervisorClassNoNamespace_;
69 
70  private:
71  static void indicateOtsAlive (const CorePropertySupervisorBase* properties = 0);
72 
73  std::string supervisorContextUID_;
74  std::string supervisorApplicationUID_;
75  std::string supervisorConfigurationPath_;
76 
77  protected:
78  // Supervisor Property names
79  // to access, use CorePropertySupervisorBase::getSupervisorProperty and
80  // CorePropertySupervisorBase::setSupervisorProperty
81  static const struct SupervisorProperties
82  {
84  : allSetNames_({&CheckUserLockRequestTypes,
85  &RequireUserLockRequestTypes,
86  &AutomatedRequestTypes,
87  &AllowNoLoginRequestTypes,
88  &RequireSecurityRequestTypes,
89  &NoXmlWhiteSpaceRequestTypes,
90  &NonXMLRequestTypes})
91  {
92  }
93 
94  const std::string UserPermissionsThreshold = "UserPermissionsThreshold";
95  const std::string UserGroupsAllowed = "UserGroupsAllowed";
96  const std::string UserGroupsDisallowed = "UserGroupsDisallowed";
97 
98  const std::string CheckUserLockRequestTypes = "CheckUserLockRequestTypes";
99  const std::string RequireUserLockRequestTypes = "RequireUserLockRequestTypes";
100  const std::string AutomatedRequestTypes = "AutomatedRequestTypes";
101  const std::string AllowNoLoginRequestTypes = "AllowNoLoginRequestTypes";
102  const std::string RequireSecurityRequestTypes = "RequireSecurityRequestTypes";
103 
104  const std::string NoXmlWhiteSpaceRequestTypes = "NoXmlWhiteSpaceRequestTypes";
105  const std::string NonXMLRequestTypes = "NonXMLRequestTypes";
106 
107  const std::set<const std::string*> allSetNames_;
108  } SUPERVISOR_PROPERTIES;
109 
110  private:
111  // property private members
112  void checkSupervisorPropertySetup (void);
113  volatile bool propertiesAreSetup_;
114 
115  // for public access to property map,..
116  // use CorePropertySupervisorBase::getSupervisorProperty and
117  // CorePropertySupervisorBase::setSupervisorProperty
118  std::map<std::string, std::string> propertyMap_;
119  struct CoreSupervisorPropertyStruct
120  {
121  CoreSupervisorPropertyStruct()
122  : allSets_({&CheckUserLockRequestTypes,
123  &RequireUserLockRequestTypes,
124  &AutomatedRequestTypes,
125  &AllowNoLoginRequestTypes,
126  &RequireSecurityRequestTypes,
127  &NoXmlWhiteSpaceRequestTypes,
128  &NonXMLRequestTypes})
129  {
130  }
131 
132  std::map<std::string, WebUsers::permissionLevel_t> UserPermissionsThreshold;
133  std::map<std::string, std::string> UserGroupsAllowed;
134  std::map<std::string, std::string> UserGroupsDisallowed;
135 
136  std::set<std::string> CheckUserLockRequestTypes;
137  std::set<std::string> RequireUserLockRequestTypes;
138  std::set<std::string> AutomatedRequestTypes;
139  std::set<std::string> AllowNoLoginRequestTypes;
140  std::set<std::string> RequireSecurityRequestTypes;
141 
142  std::set<std::string> NoXmlWhiteSpaceRequestTypes;
143  std::set<std::string> NonXMLRequestTypes;
144 
145  std::set<std::set<std::string>*> allSets_;
146  } propertyStruct_;
147 
148  public:
149  void resetPropertiesAreSetup (void)
150  {
151  propertiesAreSetup_ = false;
152  } // forces reload of properties from configuration
153  ConfigurationTree getSupervisorTreeNode(void);
154 
155  void loadUserSupervisorProperties (void);
156  template<class T>
157  void setSupervisorProperty (
158  const std::string& propertyName, const T& propertyValue)
159  {
160  std::stringstream ss;
161  ss << propertyValue;
162  setSupervisorProperty(propertyName, ss.str());
163  } //end setSupervisorProperty()
164  void setSupervisorProperty (const std::string& propertyName,
165  const std::string& propertyValue);
166  template<class T>
167  void addSupervisorProperty (
168  const std::string& propertyName, const T& propertyValue)
169  {
170  // prepend new values.. since map/set extraction takes the first value encountered
171  std::stringstream ss;
172  ss << propertyValue << " | " << getSupervisorProperty(propertyName);
173  setSupervisorProperty(propertyName, ss.str());
174  } //end addSupervisorProperty()
175  void addSupervisorProperty (const std::string& propertyName, const std::string& propertyValue);
176  template<class T>
177  T getSupervisorProperty (
178  const std::string& propertyName)
179  {
180  // check if need to setup properties
181  checkSupervisorPropertySetup();
182 
183  auto it = propertyMap_.find(propertyName);
184  if(it == propertyMap_.end())
185  {
186  __SS__ << "Could not find property named " << propertyName << __E__;
187  __SS_THROW__;
188  }
189  return StringMacros::validateValueForDefaultStringDataType<T>(it->second);
190  } //end getSupervisorProperty()
191  template<class T>
192  T getSupervisorProperty (
193  const std::string& propertyName, const T& defaultValue)
194  {
195  // check if need to setup properties
196  checkSupervisorPropertySetup();
197 
198  auto it = propertyMap_.find(propertyName);
199  if(it == propertyMap_.end())
200  {
201  //not found, so returning default value
202  return defaultValue;
203  }
204  return StringMacros::validateValueForDefaultStringDataType<T>(it->second);
205  } //end getSupervisorProperty()
206  std::string getSupervisorProperty (const std::string& propertyName);
207  std::string getSupervisorProperty (const std::string& propertyName, const std::string& defaultValue);
208  WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold (const std::string& requestType);
209 };
210 
211 // clang-format on
212 
213 } // namespace ots
214 
215 #endif