otsdaq  v2_04_01
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/TablePlugins/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  AllSupervisorInfo allSupervisorInfo_;
33  ConfigurationManager* theConfigurationManager_;
34 
35  virtual void setSupervisorPropertyDefaults(
36  void); // override to control supervisor specific defaults
37  virtual void forceSupervisorPropertyValues(void)
38  {
39  ;
40  } // 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(
47  const std::string& permissionsString,
48  std::map<std::string, WebUsers::permissionLevel_t>& permissionsMap);
49  static bool doPermissionsGrantAccess(
50  std::map<std::string, WebUsers::permissionLevel_t>& permissionLevelsMap,
51  std::map<std::string, WebUsers::permissionLevel_t>& permissionThresholdsMap);
52 
53  ConfigurationTree getContextTreeNode(void) const
54  {
55  return theConfigurationManager_->getNode(
56  theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName());
57  }
58  ConfigurationTree getSupervisorTableNode(void) const
59  {
60  return getContextTreeNode().getNode(supervisorConfigurationPath_);
61  }
62 
63  const std::string& getContextUID(void) const { return supervisorContextUID_; }
64  const std::string& getSupervisorUID(void) const { return supervisorApplicationUID_; }
65  const std::string& getSupervisorConfigurationPath(void) const
66  {
67  return supervisorConfigurationPath_;
68  }
69 
70  protected:
71  const std::string supervisorClass_;
72  const std::string supervisorClassNoNamespace_;
73 
74  private:
75  static void indicateOtsAlive(const CorePropertySupervisorBase* properties = 0);
76 
77  std::string supervisorContextUID_;
78  std::string supervisorApplicationUID_;
79  std::string supervisorConfigurationPath_;
80 
81  protected:
82  // Supervisor Property names
83  // to access, use CorePropertySupervisorBase::getSupervisorProperty and
84  // CorePropertySupervisorBase::setSupervisorProperty
85  static const struct SupervisorProperties
86  {
88  : allSetNames_({&CheckUserLockRequestTypes,
89  &RequireUserLockRequestTypes,
90  &AutomatedRequestTypes,
91  &AllowNoLoginRequestTypes,
92  &NoXmlWhiteSpaceRequestTypes,
93  &NonXMLRequestTypes})
94  {
95  }
96 
97  const std::string UserPermissionsThreshold = "UserPermissionsThreshold";
98  const std::string UserGroupsAllowed = "UserGroupsAllowed";
99  const std::string UserGroupsDisallowed = "UserGroupsDisallowed";
100 
101  const std::string CheckUserLockRequestTypes = "CheckUserLockRequestTypes";
102  const std::string RequireUserLockRequestTypes = "RequireUserLockRequestTypes";
103  const std::string AutomatedRequestTypes = "AutomatedRequestTypes";
104  const std::string AllowNoLoginRequestTypes = "AllowNoLoginRequestTypes";
105 
106  const std::string NoXmlWhiteSpaceRequestTypes = "NoXmlWhiteSpaceRequestTypes";
107  const std::string NonXMLRequestTypes = "NonXMLRequestTypes";
108 
109  const std::set<const std::string*> allSetNames_;
110  } SUPERVISOR_PROPERTIES;
111 
112  private:
113  // property private members
114  void checkSupervisorPropertySetup(void);
115  volatile bool propertiesAreSetup_;
116 
117  // for public access to property map,..
118  // use CorePropertySupervisorBase::getSupervisorProperty and
119  // CorePropertySupervisorBase::setSupervisorProperty
120  std::map<std::string, std::string> propertyMap_;
121  struct CoreSupervisorPropertyStruct
122  {
123  CoreSupervisorPropertyStruct()
124  : allSets_({&CheckUserLockRequestTypes,
125  &RequireUserLockRequestTypes,
126  &AutomatedRequestTypes,
127  &AllowNoLoginRequestTypes,
128  &NoXmlWhiteSpaceRequestTypes,
129  &NonXMLRequestTypes})
130  {
131  }
132 
133  std::map<std::string, WebUsers::permissionLevel_t> UserPermissionsThreshold;
134  std::map<std::string, std::string> UserGroupsAllowed;
135  std::map<std::string, std::string> UserGroupsDisallowed;
136 
137  std::set<std::string> CheckUserLockRequestTypes;
138  std::set<std::string> RequireUserLockRequestTypes;
139  std::set<std::string> AutomatedRequestTypes;
140  std::set<std::string> AllowNoLoginRequestTypes;
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(const std::string& propertyName, const T& propertyValue)
158  {
159  std::stringstream ss;
160  ss << propertyValue;
161  setSupervisorProperty(propertyName, ss.str());
162  }
163  void setSupervisorProperty(const std::string& propertyName,
164  const std::string& propertyValue);
165  template<class T>
166  void addSupervisorProperty(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  }
173  void addSupervisorProperty(const std::string& propertyName,
174  const std::string& propertyValue);
175  template<class T>
176  T getSupervisorProperty(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  }
189  std::string getSupervisorProperty(const std::string& propertyName);
190  WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold(
191  const std::string& requestType);
192 };
193 
194 } // namespace ots
195 
196 #endif