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

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

90  : coral::Service( key ),
91  m_isInitialized( false ),
92  m_inputFileName( "" ),
93  m_data(),
94  m_mutexLock(),
95  m_callbackID(0)
96 {
97  boost::function1<void, std::string> cb(boost::bind(&cond::XMLAuthenticationService::XMLAuthenticationService::setAuthenticationPath, this, _1));
98 
99  coral::Property* pm = dynamic_cast<coral::Property*>(coral::Context::instance().PropertyManager().property(Auth::COND_AUTH_PATH_PROPERTY));
100  if(pm){
101  setAuthenticationPath( pm->get() );
102  m_callbackID = pm->registerCallback(cb);
103  }
104 }
static PFTauRenderPlugin instance
static const std::string 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.
std::map< std::string, DataSourceEntry * > m_data
The structure with the authentication data.
list key
Definition: combine.py:13
std::string m_inputFileName
The input file with the data.
cond::XMLAuthenticationService::XMLAuthenticationService::~XMLAuthenticationService ( )
virtual

Standard Destructor.

Definition at line 106 of file XMLAuthenticationService.cc.

107 {
108  for ( std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.begin();
109  iConnection != m_data.end(); ++iConnection ) delete iConnection->second;
110 }
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 386 of file XMLAuthenticationService.cc.

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

387 {
388  boost::mutex::scoped_lock lock(m_mutexLock);
389  if ( ! m_isInitialized ) {
391  }
392  std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::const_iterator iConnection = m_data.find( connectionString );
393  if ( iConnection == m_data.end() )
394  throw coral::UnknownConnectionException( this->name(), connectionString );
395  return iConnection->second->credentials();
396 }
bool initialize()
Service framework related initialization.
bool m_isInitialized
Flag indicating whether the service has been initialized.
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 400 of file XMLAuthenticationService.cc.

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

402 {
403  boost::mutex::scoped_lock lock(m_mutexLock);
404  if ( ! m_isInitialized ) {
406  }
407  std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::const_iterator iConnection = m_data.find( connectionString );
408  if ( iConnection == m_data.end() )
409  throw coral::UnknownConnectionException( this->name(), connectionString );
410  return iConnection->second->credentials( role );
411 }
bool initialize()
Service framework related initialization.
bool m_isInitialized
Flag indicating whether the service has been initialized.
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 335 of file XMLAuthenticationService.cc.

References Debug, create_public_lumi_plots::log, python.rootplot.argparse::message, valtools::processFile(), fetchall_from_DQM_v2::release, reset(), query::result, AlCaHLTBitMon_QueryRunRegistry::string, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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

References cond::XMLAuthenticationService::DataSourceEntry::appendCredentialItem(), cond::XMLAuthenticationService::DataSourceEntry::appendCredentialItemForRole(), cont, cond::FileReader::content(), Debug, analyzePatCleaning_cfg::inputFile, create_public_lumi_plots::log, python.rootplot.argparse::message, mergeVDriftHistosByStation::name, geometryXMLtoCSV::parser, cmsHarvester::path, cond::FileReader::read(), fetchall_from_DQM_v2::release, query::result, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

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

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

376  {
377  for ( std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.begin();
378  iConnection != m_data.end(); ++iConnection ) delete iConnection->second;
379  m_data.clear();
380  m_isInitialized = false;
381 }
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 113 of file XMLAuthenticationService.cc.

References cmsHarvester::path, reset(), and XML_AUTHENTICATION_FILE.

Referenced by XMLAuthenticationService().

114 {
115  boost::filesystem::path boostAuthPath( inputPath );
116  if(boost::filesystem::is_directory(boostAuthPath)){
118  }
119 
120  m_inputFileName = boostAuthPath.string();
121  reset();
122 }
tuple path
else: Piece not in the list, fine.
constexpr 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 415 of file XMLAuthenticationService.cc.

References Debug, LaserDQM_cfg::fileNames, contentValuesFiles::fullPath, create_public_lumi_plots::log, cmsHarvester::path, and AlCaHLTBitMon_QueryRunRegistry::string.

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