00001 #ifndef _ots_CorePropertySupervisorBase_h_
00002 #define _ots_CorePropertySupervisorBase_h_
00003
00004
00005 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
00006 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
00007 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00008 #include "otsdaq-core/ConfigurationInterface/ConfigurationTree.h"
00009 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
00010 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00011 #include "otsdaq-core/Macros/CoutMacros.h"
00012
00013 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
00014
00015 #pragma GCC diagnostic push
00016 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
00017 #include <xdaq/Application.h>
00018 #pragma GCC diagnostic pop
00019
00020
00021
00022
00023 namespace ots
00024 {
00025
00026
00027
00028
00029 class CorePropertySupervisorBase
00030 {
00031
00032 public:
00033 CorePropertySupervisorBase (xdaq::Application* application);
00034 virtual ~CorePropertySupervisorBase (void);
00035
00036
00037 virtual void setSupervisorPropertyDefaults (void);
00038 virtual void forceSupervisorPropertyValues (void) {;}
00039
00040 void getRequestUserInfo (WebUsers::RequestUserInfo& requestUserInfo);
00041
00042
00043 static void extractPermissionsMapFromString (const std::string& permissionsString, std::map<std::string,WebUsers::permissionLevel_t>& permissionsMap);
00044 static bool doPermissionsGrantAccess (std::map<std::string,WebUsers::permissionLevel_t>& permissionLevelsMap, std::map<std::string,WebUsers::permissionLevel_t>& permissionThresholdsMap);
00045
00046 ConfigurationTree getContextTreeNode (void) const { return theConfigurationManager_->getNode(theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getConfigurationName()); }
00047 protected:
00048
00049
00050 ConfigurationManager* theConfigurationManager_;
00051
00052 std::string supervisorClass_;
00053 std::string supervisorClassNoNamespace_;
00054
00055 std::string supervisorContextUID_;
00056 std::string supervisorApplicationUID_;
00057 std::string supervisorConfigurationPath_;
00058
00059 AllSupervisorInfo allSupervisorInfo_;
00060
00061
00062
00063 static const struct SupervisorProperties
00064 {
00065 SupervisorProperties()
00066 : allSetNames_({&CheckUserLockRequestTypes,&RequireUserLockRequestTypes,
00067 &AutomatedRequestTypes,&AllowNoLoginRequestTypes,
00068 &NoXmlWhiteSpaceRequestTypes,&NonXMLRequestTypes})
00069 {}
00070
00071 const std::string UserPermissionsThreshold = "UserPermissionsThreshold";
00072 const std::string UserGroupsAllowed = "UserGroupsAllowed";
00073 const std::string UserGroupsDisallowed = "UserGroupsDisallowed";
00074
00075 const std::string CheckUserLockRequestTypes = "CheckUserLockRequestTypes";
00076 const std::string RequireUserLockRequestTypes = "RequireUserLockRequestTypes";
00077 const std::string AutomatedRequestTypes = "AutomatedRequestTypes";
00078 const std::string AllowNoLoginRequestTypes = "AllowNoLoginRequestTypes";
00079
00080 const std::string NoXmlWhiteSpaceRequestTypes = "NoXmlWhiteSpaceRequestTypes";
00081 const std::string NonXMLRequestTypes = "NonXMLRequestTypes";
00082
00083 const std::set<const std::string*> allSetNames_;
00084 } SUPERVISOR_PROPERTIES;
00085
00086 private:
00087
00088 void checkSupervisorPropertySetup (void);
00089 volatile bool propertiesAreSetup_;
00090
00091
00092
00093 std::map<std::string, std::string> propertyMap_;
00094 struct CoreSupervisorPropertyStruct
00095 {
00096 CoreSupervisorPropertyStruct()
00097 : allSets_ ({&CheckUserLockRequestTypes,&RequireUserLockRequestTypes,
00098 &AutomatedRequestTypes,&AllowNoLoginRequestTypes,
00099 &NoXmlWhiteSpaceRequestTypes,&NonXMLRequestTypes})
00100 {}
00101
00102 std::map<std::string,WebUsers::permissionLevel_t> UserPermissionsThreshold;
00103 std::map<std::string,std::string> UserGroupsAllowed;
00104 std::map<std::string,std::string> UserGroupsDisallowed;
00105
00106 std::set<std::string> CheckUserLockRequestTypes;
00107 std::set<std::string> RequireUserLockRequestTypes;
00108 std::set<std::string> AutomatedRequestTypes;
00109 std::set<std::string> AllowNoLoginRequestTypes;
00110
00111 std::set<std::string> NoXmlWhiteSpaceRequestTypes;
00112 std::set<std::string> NonXMLRequestTypes;
00113
00114 std::set< std::set<std::string>* > allSets_;
00115 } propertyStruct_;
00116
00117 public:
00118 void resetPropertiesAreSetup (void) { propertiesAreSetup_ = false; }
00119 ConfigurationTree getSupervisorTreeNode (void);
00120
00121 void loadUserSupervisorProperties (void);
00122 template<class T>
00123 void setSupervisorProperty (const std::string& propertyName, const T& propertyValue)
00124 {
00125 std::stringstream ss;
00126 ss << propertyValue;
00127 setSupervisorProperty(propertyName,ss.str());
00128 }
00129 void setSupervisorProperty (const std::string& propertyName, const std::string& propertyValue);
00130 template<class T>
00131 void addSupervisorProperty (const std::string& propertyName, const T& propertyValue)
00132 {
00133
00134 std::stringstream ss;
00135 ss << propertyValue << " | " << getSupervisorProperty(propertyName);
00136 setSupervisorProperty(propertyName,ss.str());
00137 }
00138 void addSupervisorProperty (const std::string& propertyName, const std::string& propertyValue);
00139 template<class T>
00140 T getSupervisorProperty (const std::string& propertyName)
00141 {
00142
00143 checkSupervisorPropertySetup();
00144
00145 auto it = propertyMap_.find(propertyName);
00146 if(it == propertyMap_.end())
00147 {
00148 __SS__ << "Could not find property named " << propertyName << __E__;
00149 __SS_THROW__;
00150 }
00151 return StringMacros::validateValueForDefaultStringDataType<T>(it->second);
00152 }
00153 std::string getSupervisorProperty(const std::string& propertyName);
00154 WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold(const std::string& requestType);
00155
00156 };
00157
00158 }
00159
00160 #endif