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