test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
const
coral::IAuthenticationCredentials & 
credentials (const std::string &connectionString, const std::string &role) const
 
void setAuthenticationPath (const std::string &inputPath)
 Sets the input file name. More...
 
 XMLAuthenticationService (const std::string &name)
 Standard Constructor. More...
 
virtual ~XMLAuthenticationService ()
 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 85 of file XMLAuthenticationService.h.

Constructor & Destructor Documentation

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

Standard Constructor.

Definition at line 88 of file XMLAuthenticationService.cc.

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

89  : coral::Service( key ),
90  m_isInitialized( false ),
91  m_inputFileName( "" ),
92  m_data(),
93  m_mutexLock(),
94  m_callbackID(0)
95 {
96  boost::function1<void, std::string> cb(boost::bind(&cond::XMLAuthenticationService::XMLAuthenticationService::setAuthenticationPath, this, _1));
97 
98  coral::Property* pm = dynamic_cast<coral::Property*>(coral::Context::instance().PropertyManager().property(auth::COND_AUTH_PATH_PROPERTY));
99  if(pm){
100  setAuthenticationPath( pm->get() );
101  m_callbackID = pm->registerCallback(cb);
102  }
103 }
static PFTauRenderPlugin instance
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
bool m_isInitialized
Flag indicating whether the service has been initialized.
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
std::string m_inputFileName
The input file with the data.
cond::XMLAuthenticationService::XMLAuthenticationService::~XMLAuthenticationService ( )
virtual

Standard Destructor.

Definition at line 105 of file XMLAuthenticationService.cc.

106 {
107  for ( std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.begin();
108  iConnection != m_data.end(); ++iConnection ) delete iConnection->second;
109 }
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.

Member Function Documentation

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

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 385 of file XMLAuthenticationService.cc.

References autoCondHLT::connectionString, initialize(), CommonMethods::lock(), and mergeVDriftHistosByStation::name.

386 {
387  boost::mutex::scoped_lock lock(m_mutexLock);
388  if ( ! m_isInitialized ) {
390  }
391  std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::const_iterator iConnection = m_data.find( connectionString );
392  if ( iConnection == m_data.end() )
393  throw coral::UnknownConnectionException( this->name(), connectionString );
394  return iConnection->second->credentials();
395 }
bool initialize()
Service framework related initialization.
bool m_isInitialized
Flag indicating whether the service has been initialized.
string connectionString
Definition: autoCondHLT.py:4
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
const coral::IAuthenticationCredentials & cond::XMLAuthenticationService::XMLAuthenticationService::credentials ( const std::string &  connectionString,
const std::string &  role 
) const

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 399 of file XMLAuthenticationService.cc.

References autoCondHLT::connectionString, initialize(), CommonMethods::lock(), and mergeVDriftHistosByStation::name.

401 {
402  boost::mutex::scoped_lock lock(m_mutexLock);
403  if ( ! m_isInitialized ) {
405  }
406  std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::const_iterator iConnection = m_data.find( connectionString );
407  if ( iConnection == m_data.end() )
408  throw coral::UnknownConnectionException( this->name(), connectionString );
409  return iConnection->second->credentials( role );
410 }
bool initialize()
Service framework related initialization.
bool m_isInitialized
Flag indicating whether the service has been initialized.
string connectionString
Definition: autoCondHLT.py:4
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
bool cond::XMLAuthenticationService::XMLAuthenticationService::initialize ( )
private

Service framework related initialization.

Definition at line 334 of file XMLAuthenticationService.cc.

References Debug, mvaPFMET_cff::inputFileNames, dqm-mbProfile::log, python.rootplot.argparse::message, valtools::processFile(), fetchall_from_DQM_v2::release, reset(), mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, XERCES_CPP_NAMESPACE_USE::transcode(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

335 {
336  coral::MessageStream log("cond::XMLAuthenticationService::initialize");
337  std::set< std::string > inputFileNames = this->verifyFileName();
338  if ( inputFileNames.empty() )
339  {
340  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
341  //std::cout<< "Could not open \"" << m_inputFileName << "\" for reading" << std::endl;
342  log<<coral::Debug<<"Could not open \"" << m_inputFileName << "\" for reading" <<coral::MessageStream::endmsg;
343  return false;
344  }
345 
346  try
347  {
349  }
350  catch ( const xercesc::XMLException& toCatch )
351  {
352  char* message = xercesc::XMLString::transcode( toCatch.getMessage() );
353  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
354  //log << seal::Msg::Error << message << seal::flush;
355  log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg;
356  xercesc::XMLString::release( &message );
357  return false;
358  }
359 
360  bool result = false;
361  for ( std::set< std::string >::const_reverse_iterator iFileName = inputFileNames.rbegin();
362  iFileName != inputFileNames.rend(); ++iFileName ) {
363  if ( this->processFile( *iFileName ) ) {
364  result = true;
365  }
366  }
367 
369 
371  if(!m_isInitialized) reset();
372  return result;
373 }
tuple inputFileNames
Definition: mvaPFMET_cff.py:73
void xercesTerminate()
Definition: Xerces.cc:22
void xercesInitialize()
Definition: Xerces.cc:17
bool m_isInitialized
Flag indicating whether the service has been initialized.
tuple result
Definition: mps_fire.py:83
std::set< std::string > verifyFileName()
Verifies the existence of the authentication files.
XMLCh * transcode(const T &fInput)
bool processFile(const std::string &inputFileName)
Parses an xml file.
std::string m_inputFileName
The input file with the data.
const bool Debug
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 124 of file XMLAuthenticationService.cc.

References cond::XMLAuthenticationService::DataSourceEntry::appendCredentialItem(), cond::XMLAuthenticationService::DataSourceEntry::appendCredentialItemForRole(), generateEDF::cont, cond::FileReader::content(), Debug, analyzePatCleaning_cfg::inputFile, dqm-mbProfile::log, python.rootplot.argparse::message, mergeVDriftHistosByStation::name, mps_alisetup::parser, fed_dqm_sourceclient-live_cfg::path, cond::FileReader::read(), fetchall_from_DQM_v2::release, mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, XERCES_CPP_NAMESPACE_USE::transcode(), and cms::Exception::what().

125 {
126  coral::MessageStream log("cond::XMLAuthenticationService::processFile");
127  //std::cout<< "Processing file \""<< inputFileName<<"\"" <<std::endl;
128  bool result = true;
129 
131  std::string cont("");
132  try{
133  inputFile.read(inputFileName);
134  cont = inputFile.content();
135  } catch (const cond::Exception& exc){
136  log << coral::Error << "File \"" << inputFileName << "\" not found."<<std::string(exc.what())<<coral::MessageStream::endmsg;
137  return false;
138  }
139 
140  // check the
142 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47
143  std::string name = filePath.filename().string();
144 #else
145  std::string name = filePath.leaf();
146 #endif
147 
168  xercesc::MemBufInputSource* memBufInputSource = 0;
169 
170  try
171  {
172  xercesc::XercesDOMParser parser;
173  parser.setValidationScheme( xercesc::XercesDOMParser::Val_Always );
174  parser.setDoNamespaces( true );
175 
176  xercesc::HandlerBase errorHandler;
177  parser.setErrorHandler( &errorHandler );
178 
179 
180  const char* bufferId="InMemoryDocument";
181  const char* buffer = cont.c_str();
182 
183  memBufInputSource = new xercesc::MemBufInputSource( (const XMLByte*)buffer,strlen(buffer),bufferId,false );
184 
185  parser.parse(*memBufInputSource);
186 
187  xercesc::DOMDocument* document = parser.getDocument();
188 
189  XMLCh tempStr[20];
190  xercesc::XMLString::transcode( "connection", tempStr, 19);
191 
192  xercesc::DOMNodeList* connectionList = document->getElementsByTagName( tempStr );
193 
194  if ( connectionList )
195  {
196  XMLSize_t numberOfConnections = connectionList->getLength();
197 
198  for ( XMLSize_t iConnection = 0; iConnection < numberOfConnections; ++iConnection )
199  {
200  xercesc::DOMNode* connectionNode = connectionList->item( iConnection );
201 
202  if ( connectionNode )
203  {
204  char* connectionName = xercesc::XMLString::transcode( connectionNode->getAttributes()->item( 0 )->getNodeValue() );
205  std::string sConnectionName = connectionName;
206  xercesc::XMLString::release( &connectionName );
207 
208  // Locate the credential
210  std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.find( sConnectionName );
211  if ( iConnection != m_data.end() ) {
212  credential = iConnection->second;
213  // Issue a warning here.
214  //coral::MessageStream log( this, this->name(),seal::Msg::Verbose );
215  log<<coral::Debug<<"Credential parameters for connection string \""
216  << sConnectionName
217  << "\" have already been defined. Only new elements are appended, while existing will be ignored."
218  << coral::MessageStream::endmsg;
219  } else {
220  credential = new cond::XMLAuthenticationService::DataSourceEntry( this->name(), sConnectionName );
221  m_data.insert( std::make_pair( sConnectionName, credential ) );
222  }
223 
224  xercesc::DOMNodeList* parameterList = connectionNode->getChildNodes();
225 
226  if ( parameterList )
227  {
228  XMLSize_t numberOfParameters = parameterList->getLength();
229 
230  for ( XMLSize_t iParameter = 0; iParameter < numberOfParameters; ++iParameter )
231  {
232  xercesc::DOMNode* parameterNode = parameterList->item( iParameter );
233 
234  if ( parameterNode && parameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE )
235  {
236  char* nodeName = xercesc::XMLString::transcode( parameterNode->getNodeName() );
237  std::string sNodeName = nodeName;
238  xercesc::XMLString::release( &nodeName );
239 
240  if ( sNodeName == "parameter" ) { // The default parameters
241  char* parameterName = xercesc::XMLString::transcode( parameterNode->getAttributes()->item( 0 )->getNodeValue() );
242  std::string sParameterName = parameterName;
243  xercesc::XMLString::release( &parameterName );
244  char* parameterValue = xercesc::XMLString::transcode( parameterNode->getAttributes()->item( 1 )->getNodeValue() );
245  std::string sParameterValue = parameterValue;
246  xercesc::XMLString::release( &parameterValue );
247 
248  credential->appendCredentialItem( sParameterName, sParameterValue );
249  }
250  else if ( sNodeName == "role" ) { // A role
251  char* roleName = xercesc::XMLString::transcode( parameterNode->getAttributes()->item( 0 )->getNodeValue() );
252  std::string sRoleName = roleName;
253  xercesc::XMLString::release( &roleName );
254 
255  // Retrieve the parameters for the role
256  xercesc::DOMNodeList* roleParameterList = parameterNode->getChildNodes();
257 
258 
259  if ( roleParameterList )
260  {
261  XMLSize_t numberOfRoleParameters = roleParameterList->getLength();
262 
263  for ( XMLSize_t iRoleParameter = 0; iRoleParameter < numberOfRoleParameters; ++iRoleParameter )
264  {
265  xercesc::DOMNode* roleParameterNode = roleParameterList->item( iRoleParameter );
266  if ( roleParameterNode && roleParameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE )
267  {
268  char* roleNodeName = xercesc::XMLString::transcode( roleParameterNode->getNodeName() );
269  std::string sRoleNodeName = roleNodeName;
270  xercesc::XMLString::release( &roleNodeName );
271 
272  if ( sRoleNodeName == "parameter" ) {
273  char* roleParameterName = xercesc::XMLString::transcode( roleParameterNode->getAttributes()->item( 0 )->getNodeValue() );
274  std::string sRoleParameterName = roleParameterName;
275  xercesc::XMLString::release( &roleParameterName );
276  char* roleParameterValue = xercesc::XMLString::transcode( roleParameterNode->getAttributes()->item( 1 )->getNodeValue() );
277  std::string sRoleParameterValue = roleParameterValue;
278  xercesc::XMLString::release( &roleParameterValue );
279 
280  credential->appendCredentialItemForRole( sRoleParameterName, sRoleParameterValue, sRoleName );
281  }
282  }
283  }
284  }
285  }
286  }
287  }
288  }
289  }
290  }
291  }
292 
293  parser.reset();
294  }
295  catch ( const xercesc::XMLException& toCatch )
296  {
297  char* message = xercesc::XMLString::transcode( toCatch.getMessage() );
298  //coral::MessageStream log( this, this->name(),coral::Msg::Verbose );
299  //log << coral::Msg::Error << message << coral::flush;
300  log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg;
301  xercesc::XMLString::release( &message );
302  result = false;
303  }
304  catch ( const xercesc::DOMException& toCatch )
305  {
306  char* message = xercesc::XMLString::transcode( toCatch.msg );
307  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
308  //log << seal::Msg::Error << message << seal::flush;
309  log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg;
310  xercesc::XMLString::release( &message );
311  result = false;
312  }
313  catch ( const xercesc::SAXException& toCatch )
314  {
315  char* message = xercesc::XMLString::transcode( toCatch.getMessage() );
316  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
317  //log << seal::Msg::Error << message << seal::flush;
318  log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg;
319  xercesc::XMLString::release( &message );
320  result = false;
321  }
322  catch (...){
323  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
324  //log << seal::Msg::Error << "Unexpected Exception parsing file \"" << inputFileName << "\"" << seal::flush;
325  log<<coral::Error<<"Unexpected Exception parsing file \"" << inputFileName << "\"" <<coral::MessageStream::endmsg;
326  result = false;
327  }
328  if(memBufInputSource) delete memBufInputSource;
329  return result;
330 }
virtual char const * what() const
Definition: Exception.cc:141
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
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
tuple result
Definition: mps_fire.py:83
bool read(const std::string &fileName)
Definition: FileUtils.cc:6
XMLCh * transcode(const T &fInput)
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
const std::string & content() const
Definition: FileUtils.h:31
void appendCredentialItem(const std::string &item, const std::string &value)
const bool Debug
void cond::XMLAuthenticationService::XMLAuthenticationService::reset ( void  )
private

Reset parsed data.

Definition at line 375 of file XMLAuthenticationService.cc.

Referenced by MatrixReader.MatrixReader::__init__(), and MatrixReader.MatrixReader::showRaw().

375  {
376  for ( std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.begin();
377  iConnection != m_data.end(); ++iConnection ) delete iConnection->second;
378  m_data.clear();
379  m_isInitialized = false;
380 }
bool m_isInitialized
Flag indicating whether the service has been initialized.
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
void cond::XMLAuthenticationService::XMLAuthenticationService::setAuthenticationPath ( const std::string &  inputPath)

Sets the input file name.

Definition at line 112 of file XMLAuthenticationService.cc.

References fed_dqm_sourceclient-live_cfg::path, reset(), and XML_AUTHENTICATION_FILE.

Referenced by XMLAuthenticationService().

113 {
114  boost::filesystem::path boostAuthPath( inputPath );
115  if(boost::filesystem::is_directory(boostAuthPath)){
117  }
118 
119  m_inputFileName = boostAuthPath.string();
120  reset();
121 }
char XML_AUTHENTICATION_FILE[]
std::string m_inputFileName
The input file with the data.
std::set< std::string > cond::XMLAuthenticationService::XMLAuthenticationService::verifyFileName ( )
private

Verifies the existence of the authentication files.

Definition at line 414 of file XMLAuthenticationService.cc.

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

415 {
416  coral::MessageStream log("cond::XMLAuthenticationService::verifyFileName");
417  std::set< std::string > fileNames;
418 
419  // Try the file name as is...
421  if ( boost::filesystem::exists( m_inputFileName ) ) {
422  if(boost::filesystem::is_directory( m_inputFileName )){
423  //seal::MessageStream log( this, this->name(),seal::Msg::Verbose );
424  log <<coral::Error << "Provided path \"" << m_inputFileName << "\" is a directory." <<coral::MessageStream::endmsg;
425  return fileNames;
426  }
427  boost::filesystem::path& fullPath = filePath.normalize();
428  fileNames.insert( fullPath.string() );
429  if(filePath.is_complete()) return fileNames;
430  }
431 
432  // Try to find other files in the path variable
433  const char* thePathVariable = ::getenv( "CORAL_AUTH_PATH" );
434  if ( ! thePathVariable ) return fileNames;
435  log<<coral::Debug<< "File \"" << m_inputFileName << "\" not found in the current directory. Trying in the search path." <<coral::MessageStream::endmsg;
436 
437  std::string searchPath(thePathVariable);
438  //std::cout<<"searchPath "<<searchPath<<std::endl;
439  if(boost::filesystem::exists(searchPath)){
440  if(!boost::filesystem::is_directory( searchPath )){
441  log<<coral::Debug<<"Search path \"" << searchPath << "\" is not a directory."<<coral::MessageStream::endmsg;
442  return fileNames;
443  }
444  boost::filesystem::path fullPath( searchPath );
445  fullPath /= filePath;
446  fileNames.insert( fullPath.string() );
447  } else {
448  log<<coral::Debug<<"Search path \"" << searchPath << "\" does not exist."<<coral::MessageStream::endmsg;
449  return fileNames;
450  }
451 
452  return fileNames;
453 }
std::string m_inputFileName
The input file with the data.
tuple fileNames
Definition: LaserDQM_cfg.py:34
const bool Debug

Member Data Documentation

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

Definition at line 140 of file XMLAuthenticationService.h.

Referenced by XMLAuthenticationService().

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

The structure with the authentication data.

Definition at line 135 of file XMLAuthenticationService.h.

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

The input file with the data.

Definition at line 132 of file XMLAuthenticationService.h.

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

Flag indicating whether the service has been initialized.

Definition at line 129 of file XMLAuthenticationService.h.

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

the mutex lock

Definition at line 138 of file XMLAuthenticationService.h.