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"
33 : m_serviceName(serviceName),
34 m_connectionName(connectionName),
35 m_default(new coral::AuthenticationCredentials(serviceName)),
40 for (std::map<std::string, coral::AuthenticationCredentials*>::iterator iData = m_data.begin(); iData != m_data.end();
47 m_default->registerItem(item, value);
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;
57 iRole->second->registerItem(item, value);
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");
115 inputFile.
read(inputFileName);
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";
158 const char*
buffer = cont.c_str();
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();
202 XMLSize_t numberOfParameters = parameterList->getLength();
204 for (XMLSize_t iParameter = 0; iParameter < numberOfParameters; ++iParameter) {
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());
290 log <<
coral::Error <<
"Unexpected Exception parsing file \"" << inputFileName <<
"\""
291 << coral::MessageStream::endmsg;
294 if (memBufInputSource)
295 delete memBufInputSource;
300 coral::MessageStream
log(
"cond::XMLAuthenticationService::initialize");
302 if (inputFileNames.empty()) {
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();
322 iFileName != inputFileNames.rend();
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 =
353 m_data.find(connectionString);
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 =
366 m_data.find(connectionString);
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;
386 fileNames.insert(fullPath.string());
387 if (filePath.is_absolute())
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;
407 fileNames.insert(fullPath.string());
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)
static std::vector< std::string > checklist log
Base exception class for the object to relational access.
bool initialize()
Service framework related initialization.
tuple cont
load Luminosity info ##
static PFTauRenderPlugin instance
~XMLAuthenticationService() override
Standard Destructor.
string filePath
DQM Environment
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.
bool read(const std::string &fileName)
XMLAuthenticationService(const std::string &name)
Standard Constructor.
tuple key
prepare the HTCondor submission files and eventually submit them
char const * what() const noexceptoverride
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
const std::string & content() const
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
const coral::IAuthenticationCredentials & credentials() const
constexpr char XML_AUTHENTICATION_FILE[]
~DataSourceEntry()
Destructor.
void reset(double vett[256])