CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
cond::XMLAuthenticationService::XMLAuthenticationService Class Reference

#include <XMLAuthenticationService.h>

Inheritance diagram for cond::XMLAuthenticationService::XMLAuthenticationService:

Public Member Functions

const coral::IAuthenticationCredentials & credentials (const std::string &connectionString) const override
 
const coral::IAuthenticationCredentials & credentials (const std::string &connectionString, const std::string &role) const override
 
void setAuthenticationPath (const std::string &inputPath)
 Sets the input file name. More...
 
 XMLAuthenticationService (const std::string &name)
 Standard Constructor. More...
 
 ~XMLAuthenticationService () override
 Standard Destructor. More...
 

Private Member Functions

bool initialize ()
 Service framework related initialization. More...
 
bool processFile (const std::string &inputFileName)
 Parses an xml file. More...
 
void reset ()
 Reset parsed data. More...
 
std::set< std::string > verifyFileName ()
 Verifies the existence of the authentication files. More...
 

Private Attributes

coral::Property::CallbackID m_callbackID
 
std::map< std::string, DataSourceEntry * > m_data
 The structure with the authentication data. More...
 
std::string m_inputFileName
 The input file with the data. More...
 
bool m_isInitialized
 Flag indicating whether the service has been initialized. More...
 
boost::mutex m_mutexLock
 the mutex lock More...
 

Detailed Description

Definition at line 78 of file XMLAuthenticationService.h.

Constructor & Destructor Documentation

◆ XMLAuthenticationService()

cond::XMLAuthenticationService::XMLAuthenticationService::XMLAuthenticationService ( const std::string &  name)
explicit

Standard Constructor.

Definition at line 77 of file XMLAuthenticationService.cc.

References cond::auth::COND_AUTH_PATH_PROPERTY, instance, m_callbackID, and setAuthenticationPath().

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(
81 
82  coral::Property* pm = dynamic_cast<coral::Property*>(
83  coral::Context::instance().PropertyManager().property(auth::COND_AUTH_PATH_PROPERTY));
84  if (pm) {
85  setAuthenticationPath(pm->get());
86  m_callbackID = pm->registerCallback(cb);
87  }
88 }
static PFTauRenderPlugin instance
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:50
bool m_isInitialized
Flag indicating whether the service has been initialized.
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
std::string m_inputFileName
The input file with the data.

◆ ~XMLAuthenticationService()

cond::XMLAuthenticationService::XMLAuthenticationService::~XMLAuthenticationService ( )
override

Standard Destructor.

Definition at line 90 of file XMLAuthenticationService.cc.

90  {
91  for (std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::iterator iConnection = m_data.begin();
92  iConnection != m_data.end();
93  ++iConnection)
94  delete iConnection->second;
95 }
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.

Member Function Documentation

◆ credentials() [1/2]

const coral::IAuthenticationCredentials & cond::XMLAuthenticationService::XMLAuthenticationService::credentials ( const std::string &  connectionString) const
override

Returns a reference to the credentials object for a given connection string. If the connection string is not known to the service an UnknownConnectionException is thrown.

Definition at line 346 of file XMLAuthenticationService.cc.

References l1RCTOmdsFedVectorProducer_cfi::connectionString, initialize(), CommonMethods::lock(), and Skims_PA_cff::name.

347  {
348  boost::mutex::scoped_lock lock(m_mutexLock);
349  if (!m_isInitialized) {
351  }
352  std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::const_iterator iConnection =
353  m_data.find(connectionString);
354  if (iConnection == m_data.end())
355  throw coral::UnknownConnectionException(this->name(), connectionString);
356  return iConnection->second->credentials();
357 }
bool initialize()
Service framework related initialization.
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
bool m_isInitialized
Flag indicating whether the service has been initialized.

◆ credentials() [2/2]

const coral::IAuthenticationCredentials & cond::XMLAuthenticationService::XMLAuthenticationService::credentials ( const std::string &  connectionString,
const std::string &  role 
) const
override

Returns a reference to the credentials object for a given connection string. If the connection string is not known to the service an UnknownConnectionException is thrown. If the role is not known to the service an UnknownRoleException is thrown.

Definition at line 359 of file XMLAuthenticationService.cc.

References l1RCTOmdsFedVectorProducer_cfi::connectionString, initialize(), CommonMethods::lock(), and Skims_PA_cff::name.

360  {
361  boost::mutex::scoped_lock lock(m_mutexLock);
362  if (!m_isInitialized) {
364  }
365  std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::const_iterator iConnection =
366  m_data.find(connectionString);
367  if (iConnection == m_data.end())
368  throw coral::UnknownConnectionException(this->name(), connectionString);
369  return iConnection->second->credentials(role);
370 }
bool initialize()
Service framework related initialization.
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
bool m_isInitialized
Flag indicating whether the service has been initialized.

◆ initialize()

bool cond::XMLAuthenticationService::XMLAuthenticationService::initialize ( )
private

Service framework related initialization.

Definition at line 299 of file XMLAuthenticationService.cc.

References Debug, mitigatedMETSequence_cff::inputFileNames, dqm-mbProfile::log, fetchall_from_DQM_v2::release, reset(), mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

299  {
300  coral::MessageStream log("cond::XMLAuthenticationService::initialize");
301  std::set<std::string> inputFileNames = this->verifyFileName();
302  if (inputFileNames.empty()) {
303  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
304  //std::cout<< "Could not open \"" << m_inputFileName << "\" for reading" << std::endl;
305  log << coral::Debug << "Could not open \"" << m_inputFileName << "\" for reading" << coral::MessageStream::endmsg;
306  return false;
307  }
308 
309  try {
311  } catch (const xercesc::XMLException& toCatch) {
312  char* message = xercesc::XMLString::transcode(toCatch.getMessage());
313  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
314  //log << seal::Msg::Error << message << seal::flush;
315  log << coral::Error << std::string(message) << coral::MessageStream::endmsg;
316  xercesc::XMLString::release(&message);
317  return false;
318  }
319 
320  bool result = false;
321  for (std::set<std::string>::const_reverse_iterator iFileName = inputFileNames.rbegin();
322  iFileName != inputFileNames.rend();
323  ++iFileName) {
324  if (this->processFile(*iFileName)) {
325  result = true;
326  }
327  }
328 
330 
332  if (!m_isInitialized)
333  reset();
334  return result;
335 }
edm::ErrorSummaryEntry Error
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
bool m_isInitialized
Flag indicating whether the service has been initialized.
std::set< std::string > verifyFileName()
Verifies the existence of the authentication files.
bool processFile(const std::string &inputFileName)
Parses an xml file.
std::string m_inputFileName
The input file with the data.
const bool Debug

◆ processFile()

bool cond::XMLAuthenticationService::XMLAuthenticationService::processFile ( const std::string &  inputFileName)
private

Parses an xml file.


if(name!=XML_AUTHENTICATION_FILE){ cond::DecodingKey key; try{ key.readUserKeyString(cont); log << coral::Debug << "Decoding content of file \""<< key.dataSource()<<"""<<coral::MessageStream::endmsg; cond::FileReader dataFile; dataFile.read(key.dataSource()); cont = dataFile.content(); cont = coral::Cipher::decode(cont,key.key());
} catch (const cond::Exception& exc){ log << coral::Error << std::string(exc.what())<<coral::MessageStream::endmsg; return false; }

} else { seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log<<coral::Debug<< "Authentication file is expected standard XML."<<coral::MessageStream::endmsg; }

Definition at line 107 of file XMLAuthenticationService.cc.

References cond::XMLAuthenticationService::DataSourceEntry::appendCredentialItem(), cond::XMLAuthenticationService::DataSourceEntry::appendCredentialItemForRole(), edmScanValgrind::buffer, generateEDF::cont, Debug, dt4ml_dqm_sourceclient-live_cfg::filePath, dtResolutionTest_cfi::inputFile, InefficientDoubleROC::inputFileName, dqm-mbProfile::log, Skims_PA_cff::name, Herwig7_Dummy_ReadLHE_GEN_SIM::numberOfParameters, writedatasetfile::parser, castor_dqm_sourceclient_file_cfg::path, fetchall_from_DQM_v2::release, mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

107  {
108  coral::MessageStream log("cond::XMLAuthenticationService::processFile");
109  //std::cout<< "Processing file \""<< inputFileName<<"\"" <<std::endl;
110  bool result = true;
111 
113  std::string cont("");
114  try {
115  inputFile.read(inputFileName);
116  cont = inputFile.content();
117  } catch (const cond::Exception& exc) {
118  log << coral::Error << "File \"" << inputFileName << "\" not found." << std::string(exc.what())
119  << coral::MessageStream::endmsg;
120  return false;
121  }
122 
124  std::string name = filePath.filename().string();
125 
147  xercesc::MemBufInputSource* memBufInputSource = nullptr;
148 
149  try {
150  xercesc::XercesDOMParser parser;
151  parser.setValidationScheme(xercesc::XercesDOMParser::Val_Always);
152  parser.setDoNamespaces(true);
153 
154  xercesc::HandlerBase errorHandler;
155  parser.setErrorHandler(&errorHandler);
156 
157  const char* bufferId = "InMemoryDocument";
158  const char* buffer = cont.c_str();
159 
160  memBufInputSource = new xercesc::MemBufInputSource((const XMLByte*)buffer, strlen(buffer), bufferId, false);
161 
162  parser.parse(*memBufInputSource);
163 
164  xercesc::DOMDocument* document = parser.getDocument();
165 
166  XMLCh tempStr[20];
167  xercesc::XMLString::transcode("connection", tempStr, 19);
168 
169  xercesc::DOMNodeList* connectionList = document->getElementsByTagName(tempStr);
170 
171  if (connectionList) {
172  XMLSize_t numberOfConnections = connectionList->getLength();
173 
174  for (XMLSize_t iConnection = 0; iConnection < numberOfConnections; ++iConnection) {
175  xercesc::DOMNode* connectionNode = connectionList->item(iConnection);
176 
177  if (connectionNode) {
178  char* connectionName =
179  xercesc::XMLString::transcode(connectionNode->getAttributes()->item(0)->getNodeValue());
180  std::string sConnectionName = connectionName;
181  xercesc::XMLString::release(&connectionName);
182 
183  // Locate the credential
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;
189  // Issue a warning here.
190  //coral::MessageStream log( this, this->name(),seal::Msg::Verbose );
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;
194  } else {
195  credential = new cond::XMLAuthenticationService::DataSourceEntry(this->name(), sConnectionName);
196  m_data.insert(std::make_pair(sConnectionName, credential));
197  }
198 
199  xercesc::DOMNodeList* parameterList = connectionNode->getChildNodes();
200 
201  if (parameterList) {
202  XMLSize_t numberOfParameters = parameterList->getLength();
203 
204  for (XMLSize_t iParameter = 0; iParameter < numberOfParameters; ++iParameter) {
205  xercesc::DOMNode* parameterNode = parameterList->item(iParameter);
206 
207  if (parameterNode && parameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) {
208  char* nodeName = xercesc::XMLString::transcode(parameterNode->getNodeName());
209  std::string sNodeName = nodeName;
210  xercesc::XMLString::release(&nodeName);
211 
212  if (sNodeName == "parameter") { // The default parameters
213  char* parameterName =
214  xercesc::XMLString::transcode(parameterNode->getAttributes()->item(0)->getNodeValue());
215  std::string sParameterName = parameterName;
216  xercesc::XMLString::release(&parameterName);
217  char* parameterValue =
218  xercesc::XMLString::transcode(parameterNode->getAttributes()->item(1)->getNodeValue());
219  std::string sParameterValue = parameterValue;
220  xercesc::XMLString::release(&parameterValue);
221 
222  credential->appendCredentialItem(sParameterName, sParameterValue);
223  } else if (sNodeName == "role") { // A role
224  char* roleName =
225  xercesc::XMLString::transcode(parameterNode->getAttributes()->item(0)->getNodeValue());
226  std::string sRoleName = roleName;
227  xercesc::XMLString::release(&roleName);
228 
229  // Retrieve the parameters for the role
230  xercesc::DOMNodeList* roleParameterList = parameterNode->getChildNodes();
231 
232  if (roleParameterList) {
233  XMLSize_t numberOfRoleParameters = roleParameterList->getLength();
234 
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());
239  std::string sRoleNodeName = roleNodeName;
240  xercesc::XMLString::release(&roleNodeName);
241 
242  if (sRoleNodeName == "parameter") {
243  char* roleParameterName = xercesc::XMLString::transcode(
244  roleParameterNode->getAttributes()->item(0)->getNodeValue());
245  std::string sRoleParameterName = roleParameterName;
246  xercesc::XMLString::release(&roleParameterName);
247  char* roleParameterValue = xercesc::XMLString::transcode(
248  roleParameterNode->getAttributes()->item(1)->getNodeValue());
249  std::string sRoleParameterValue = roleParameterValue;
250  xercesc::XMLString::release(&roleParameterValue);
251 
252  credential->appendCredentialItemForRole(sRoleParameterName, sRoleParameterValue, sRoleName);
253  }
254  }
255  }
256  }
257  }
258  }
259  }
260  }
261  }
262  }
263  }
264 
265  parser.reset();
266  } catch (const xercesc::XMLException& toCatch) {
267  char* message = xercesc::XMLString::transcode(toCatch.getMessage());
268  //coral::MessageStream log( this, this->name(),coral::Msg::Verbose );
269  //log << coral::Msg::Error << message << coral::flush;
270  log << coral::Error << std::string(message) << coral::MessageStream::endmsg;
271  xercesc::XMLString::release(&message);
272  result = false;
273  } catch (const xercesc::DOMException& toCatch) {
274  char* message = xercesc::XMLString::transcode(toCatch.msg);
275  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
276  //log << seal::Msg::Error << message << seal::flush;
277  log << coral::Error << std::string(message) << coral::MessageStream::endmsg;
278  xercesc::XMLString::release(&message);
279  result = false;
280  } catch (const xercesc::SAXException& toCatch) {
281  char* message = xercesc::XMLString::transcode(toCatch.getMessage());
282  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
283  //log << seal::Msg::Error << message << seal::flush;
284  log << coral::Error << std::string(message) << coral::MessageStream::endmsg;
285  xercesc::XMLString::release(&message);
286  result = false;
287  } catch (...) {
288  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
289  //log << seal::Msg::Error << "Unexpected Exception parsing file \"" << inputFileName << "\"" << seal::flush;
290  log << coral::Error << "Unexpected Exception parsing file \"" << inputFileName << "\""
291  << coral::MessageStream::endmsg;
292  result = false;
293  }
294  if (memBufInputSource)
295  delete memBufInputSource;
296  return result;
297 }
edm::ErrorSummaryEntry Error
void appendCredentialItemForRole(const std::string &item, const std::string &value, const std::string &role)
Base exception class for the object to relational access.
Definition: Exception.h:11
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
void appendCredentialItem(const std::string &item, const std::string &value)
char const * what() const noexcept override
Definition: Exception.cc:103
const bool Debug
cont
load Luminosity info ##
Definition: generateEDF.py:628

◆ reset()

void cond::XMLAuthenticationService::XMLAuthenticationService::reset ( void  )
private

Reset parsed data.

Definition at line 337 of file XMLAuthenticationService.cc.

Referenced by MatrixReader.MatrixReader::__init__(), data_sources.json_list::__next__(), and MatrixReader.MatrixReader::showRaw().

337  {
338  for (std::map<std::string, cond::XMLAuthenticationService::DataSourceEntry*>::iterator iConnection = m_data.begin();
339  iConnection != m_data.end();
340  ++iConnection)
341  delete iConnection->second;
342  m_data.clear();
343  m_isInitialized = false;
344 }
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
bool m_isInitialized
Flag indicating whether the service has been initialized.

◆ setAuthenticationPath()

void cond::XMLAuthenticationService::XMLAuthenticationService::setAuthenticationPath ( const std::string &  inputPath)

Sets the input file name.

Definition at line 97 of file XMLAuthenticationService.cc.

References SiStripCommissioningSource_FromEDM_cfg::inputPath, castor_dqm_sourceclient_file_cfg::path, reset(), and XML_AUTHENTICATION_FILE.

Referenced by XMLAuthenticationService().

97  {
99  if (std::filesystem::is_directory(AuthPath)) {
101  }
102 
103  m_inputFileName = AuthPath.string();
104  reset();
105 }
constexpr char XML_AUTHENTICATION_FILE[]
std::string m_inputFileName
The input file with the data.

◆ verifyFileName()

std::set< std::string > cond::XMLAuthenticationService::XMLAuthenticationService::verifyFileName ( )
private

Verifies the existence of the authentication files.

Definition at line 372 of file XMLAuthenticationService.cc.

References Debug, LaserDQM_cfg::fileNames, dt4ml_dqm_sourceclient-live_cfg::filePath, contentValuesFiles::fullPath, dqm-mbProfile::log, castor_dqm_sourceclient_file_cfg::path, and AlCaHLTBitMon_QueryRunRegistry::string.

372  {
373  coral::MessageStream log("cond::XMLAuthenticationService::verifyFileName");
374  std::set<std::string> fileNames;
375 
376  // Try the file name as is...
378  if (std::filesystem::exists(m_inputFileName)) {
379  if (std::filesystem::is_directory(m_inputFileName)) {
380  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
381  log << coral::Error << "Provided path \"" << m_inputFileName << "\" is a directory."
382  << coral::MessageStream::endmsg;
383  return fileNames;
384  }
385  std::filesystem::path fullPath = filePath.lexically_normal();
386  fileNames.insert(fullPath.string());
387  if (filePath.is_absolute())
388  return fileNames;
389  }
390 
391  // Try to find other files in the path variable
392  const char* thePathVariable = std::getenv("CORAL_AUTH_PATH");
393  if (!thePathVariable)
394  return fileNames;
395  log << coral::Debug << "File \"" << m_inputFileName
396  << "\" not found in the current directory. Trying in the search path." << coral::MessageStream::endmsg;
397 
398  std::string searchPath(thePathVariable);
399  //std::cout<<"searchPath "<<searchPath<<std::endl;
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;
403  return fileNames;
404  }
405  std::filesystem::path fullPath(searchPath);
406  fullPath /= filePath;
407  fileNames.insert(fullPath.string());
408  } else {
409  log << coral::Debug << "Search path \"" << searchPath << "\" does not exist." << coral::MessageStream::endmsg;
410  return fileNames;
411  }
412 
413  return fileNames;
414 }
edm::ErrorSummaryEntry Error
std::string m_inputFileName
The input file with the data.
const bool Debug

Member Data Documentation

◆ m_callbackID

coral::Property::CallbackID cond::XMLAuthenticationService::XMLAuthenticationService::m_callbackID
private

Definition at line 130 of file XMLAuthenticationService.h.

Referenced by XMLAuthenticationService().

◆ m_data

std::map<std::string, DataSourceEntry*> cond::XMLAuthenticationService::XMLAuthenticationService::m_data
private

The structure with the authentication data.

Definition at line 125 of file XMLAuthenticationService.h.

◆ m_inputFileName

std::string cond::XMLAuthenticationService::XMLAuthenticationService::m_inputFileName
private

The input file with the data.

Definition at line 122 of file XMLAuthenticationService.h.

◆ m_isInitialized

bool cond::XMLAuthenticationService::XMLAuthenticationService::m_isInitialized
private

Flag indicating whether the service has been initialized.

Definition at line 119 of file XMLAuthenticationService.h.

◆ m_mutexLock

boost::mutex cond::XMLAuthenticationService::XMLAuthenticationService::m_mutexLock
mutableprivate

the mutex lock

Definition at line 128 of file XMLAuthenticationService.h.