4 #include "RelationalAccess/AuthenticationCredentials.h" 5 #include "CoralCommon/Cipher.h" 6 #include "RelationalAccess/AuthenticationServiceException.h" 7 #include "CoralKernel/IPropertyManager.h" 8 #include "CoralKernel/Property.h" 9 #include "CoralKernel/Context.h" 12 #include "xercesc/parsers/XercesDOMParser.hpp" 13 #include "xercesc/framework/MemBufInputSource.hpp" 14 #include "xercesc/dom/DOM.hpp" 15 #include "xercesc/sax/HandlerBase.hpp" 16 #include "xercesc/util/XMLString.hpp" 17 #include "xercesc/util/PlatformUtils.hpp" 27 #include "CoralBase/MessageStream.h" 34 m_connectionName(connectionName),
40 for (std::map<std::string, coral::AuthenticationCredentials*>::iterator iData = m_data.begin(); iData != m_data.end();
53 std::map<std::string, coral::AuthenticationCredentials*>::iterator iRole = m_data.find(role);
54 if (iRole == m_data.end()) {
55 iRole = m_data.insert(std::make_pair(role,
new coral::AuthenticationCredentials(m_serviceName))).first;
78 :
coral::
Service(
key), m_isInitialized(
false), m_inputFileName(
""), m_data(), m_mutexLock(), m_callbackID(0) {
79 boost::function1<void, std::string> cb(std::bind(
82 coral::Property* pm =
dynamic_cast<coral::Property*
>(
91 for (std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::iterator iConnection = m_data.begin();
92 iConnection != m_data.end();
94 delete iConnection->second;
99 if (std::filesystem::is_directory(AuthPath)) {
103 m_inputFileName = AuthPath.string();
108 coral::MessageStream
log(
"cond::XMLAuthenticationService::processFile");
119 << coral::MessageStream::endmsg;
147 xercesc::MemBufInputSource* memBufInputSource =
nullptr;
150 xercesc::XercesDOMParser
parser;
151 parser.setValidationScheme(xercesc::XercesDOMParser::Val_Always);
152 parser.setDoNamespaces(
true);
154 xercesc::HandlerBase errorHandler;
155 parser.setErrorHandler(&errorHandler);
157 const char* bufferId =
"InMemoryDocument";
160 memBufInputSource =
new xercesc::MemBufInputSource((
const XMLByte*)
buffer, strlen(
buffer), bufferId,
false);
162 parser.parse(*memBufInputSource);
164 xercesc::DOMDocument* document =
parser.getDocument();
167 xercesc::XMLString::transcode(
"connection", tempStr, 19);
169 xercesc::DOMNodeList* connectionList = document->getElementsByTagName(tempStr);
171 if (connectionList) {
172 XMLSize_t numberOfConnections = connectionList->getLength();
174 for (XMLSize_t iConnection = 0; iConnection < numberOfConnections; ++iConnection) {
175 xercesc::DOMNode* connectionNode = connectionList->item(iConnection);
177 if (connectionNode) {
178 char* connectionName =
179 xercesc::XMLString::transcode(connectionNode->getAttributes()->item(0)->getNodeValue());
185 std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::iterator iConnection =
186 m_data.find(sConnectionName);
187 if (iConnection != m_data.end()) {
188 credential = iConnection->second;
191 log <<
coral::Debug <<
"Credential parameters for connection string \"" << sConnectionName
192 <<
"\" have already been defined. Only new elements are appended, while existing will be ignored." 193 << coral::MessageStream::endmsg;
196 m_data.insert(std::make_pair(sConnectionName, credential));
199 xercesc::DOMNodeList* parameterList = connectionNode->getChildNodes();
205 xercesc::DOMNode* parameterNode = parameterList->item(iParameter);
207 if (parameterNode && parameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) {
208 char* nodeName = xercesc::XMLString::transcode(parameterNode->getNodeName());
212 if (sNodeName ==
"parameter") {
213 char* parameterName =
214 xercesc::XMLString::transcode(parameterNode->getAttributes()->item(0)->getNodeValue());
217 char* parameterValue =
218 xercesc::XMLString::transcode(parameterNode->getAttributes()->item(1)->getNodeValue());
223 }
else if (sNodeName ==
"role") {
225 xercesc::XMLString::transcode(parameterNode->getAttributes()->item(0)->getNodeValue());
230 xercesc::DOMNodeList* roleParameterList = parameterNode->getChildNodes();
232 if (roleParameterList) {
233 XMLSize_t numberOfRoleParameters = roleParameterList->getLength();
235 for (XMLSize_t iRoleParameter = 0; iRoleParameter < numberOfRoleParameters; ++iRoleParameter) {
236 xercesc::DOMNode* roleParameterNode = roleParameterList->item(iRoleParameter);
237 if (roleParameterNode && roleParameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) {
238 char* roleNodeName = xercesc::XMLString::transcode(roleParameterNode->getNodeName());
242 if (sRoleNodeName ==
"parameter") {
243 char* roleParameterName = xercesc::XMLString::transcode(
244 roleParameterNode->getAttributes()->item(0)->getNodeValue());
245 std::string sRoleParameterName = roleParameterName;
247 char* roleParameterValue = xercesc::XMLString::transcode(
248 roleParameterNode->getAttributes()->item(1)->getNodeValue());
249 std::string sRoleParameterValue = roleParameterValue;
266 }
catch (
const xercesc::XMLException& toCatch) {
267 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
273 }
catch (
const xercesc::DOMException& toCatch) {
274 char* message = xercesc::XMLString::transcode(toCatch.msg);
280 }
catch (
const xercesc::SAXException& toCatch) {
281 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
291 << coral::MessageStream::endmsg;
294 if (memBufInputSource)
295 delete memBufInputSource;
300 coral::MessageStream
log(
"cond::XMLAuthenticationService::initialize");
305 log <<
coral::Debug <<
"Could not open \"" << m_inputFileName <<
"\" for reading" << coral::MessageStream::endmsg;
311 }
catch (
const xercesc::XMLException& toCatch) {
312 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
321 for (std::set<std::string>::const_reverse_iterator iFileName =
inputFileNames.rbegin();
324 if (this->processFile(*iFileName)) {
332 if (!m_isInitialized)
338 for (std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::iterator iConnection = m_data.begin();
339 iConnection != m_data.end();
341 delete iConnection->second;
343 m_isInitialized =
false;
348 boost::mutex::scoped_lock
lock(m_mutexLock);
349 if (!m_isInitialized) {
352 std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::const_iterator iConnection =
354 if (iConnection == m_data.end())
356 return iConnection->second->credentials();
361 boost::mutex::scoped_lock
lock(m_mutexLock);
362 if (!m_isInitialized) {
365 std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::const_iterator iConnection =
367 if (iConnection == m_data.end())
369 return iConnection->second->credentials(role);
373 coral::MessageStream
log(
"cond::XMLAuthenticationService::verifyFileName");
378 if (std::filesystem::exists(m_inputFileName)) {
379 if (std::filesystem::is_directory(m_inputFileName)) {
381 log <<
coral::Error <<
"Provided path \"" << m_inputFileName <<
"\" is a directory." 382 << coral::MessageStream::endmsg;
392 const char* thePathVariable = std::getenv(
"CORAL_AUTH_PATH");
393 if (!thePathVariable)
396 <<
"\" not found in the current directory. Trying in the search path." << coral::MessageStream::endmsg;
400 if (std::filesystem::exists(searchPath)) {
401 if (!std::filesystem::is_directory(searchPath)) {
402 log <<
coral::Debug <<
"Search path \"" << searchPath <<
"\" is not a directory." << coral::MessageStream::endmsg;
409 log <<
coral::Debug <<
"Search path \"" << searchPath <<
"\" does not exist." << coral::MessageStream::endmsg;
edm::ErrorSummaryEntry Error
static AlgebraicMatrix initialize()
void appendCredentialItemForRole(const std::string &item, const std::string &value, const std::string &role)
const coral::IAuthenticationCredentials & credentials() const
Base exception class for the object to relational access.
bool initialize()
Service framework related initialization.
static PFTauRenderPlugin instance
~XMLAuthenticationService() override
Standard Destructor.
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const override
static constexpr const char *const COND_AUTH_PATH_PROPERTY
static const std::string serviceName
void reset()
Reset parsed data.
#define DEFINE_CORALSERVICE(type, name)
std::set< std::string > verifyFileName()
Verifies the existence of the authentication files.
XMLAuthenticationService(const std::string &name)
Standard Constructor.
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
filePath
CUSTOMIZE FOR ML.
key
prepare the HTCondor submission files and eventually submit them
bool processFile(const std::string &inputFileName)
Parses an xml file.
void appendCredentialItem(const std::string &item, const std::string &value)
coral::Property::CallbackID m_callbackID
constexpr char XML_AUTHENTICATION_FILE[]
~DataSourceEntry()
Destructor.
char const * what() const noexcept override
void reset(double vett[256])
cont
load Luminosity info ##