#include <XMLAuthenticationService.h>
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. | |
XMLAuthenticationService (const std::string &name) | |
Standard Constructor. | |
virtual | ~XMLAuthenticationService () |
Standard Destructor. | |
Private Member Functions | |
bool | initialize () |
Service framework related initialization. | |
bool | processFile (const std::string &inputFileName) |
Parses an xml file. | |
void | reset () |
Reset parsed data. | |
std::set< std::string > | verifyFileName () |
Verifies the existence of the authentication files. | |
Private Attributes | |
coral::Property::CallbackID | m_callbackID |
std::map< std::string, DataSourceEntry * > | m_data |
The structure with the authentication data. | |
std::string | m_inputFileName |
The input file with the data. | |
bool | m_isInitialized |
Flag indicating whether the service has been initialized. | |
boost::mutex | m_mutexLock |
the mutex lock |
Definition at line 85 of file XMLAuthenticationService.h.
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().
: coral::Service( key ), m_isInitialized( false ), m_inputFileName( "" ), m_data(), m_mutexLock(), m_callbackID(0) { boost::function1<void, std::string> cb(boost::bind(&cond::XMLAuthenticationService::XMLAuthenticationService::setAuthenticationPath, this, _1)); coral::Property* pm = dynamic_cast<coral::Property*>(coral::Context::instance().PropertyManager().property(Auth::COND_AUTH_PATH_PROPERTY)); if(pm){ setAuthenticationPath( pm->get() ); m_callbackID = pm->registerCallback(cb); } }
cond::XMLAuthenticationService::XMLAuthenticationService::~XMLAuthenticationService | ( | ) | [virtual] |
Standard Destructor.
Definition at line 105 of file XMLAuthenticationService.cc.
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 credentials(), CommonMethods::lock(), and mergeVDriftHistosByStation::name.
Referenced by credentials().
{ boost::mutex::scoped_lock lock(m_mutexLock); if ( ! m_isInitialized ) { const_cast< cond::XMLAuthenticationService::XMLAuthenticationService* >( this )->initialize(); } std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::const_iterator iConnection = m_data.find( connectionString ); if ( iConnection == m_data.end() ) throw coral::UnknownConnectionException( this->name(), connectionString ); return iConnection->second->credentials(); }
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 credentials(), CommonMethods::lock(), and mergeVDriftHistosByStation::name.
{ boost::mutex::scoped_lock lock(m_mutexLock); if ( ! m_isInitialized ) { const_cast< cond::XMLAuthenticationService::XMLAuthenticationService* >( this )->initialize(); } std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::const_iterator iConnection = m_data.find( connectionString ); if ( iConnection == m_data.end() ) throw coral::UnknownConnectionException( this->name(), connectionString ); return iConnection->second->credentials( role ); }
bool cond::XMLAuthenticationService::XMLAuthenticationService::initialize | ( | ) | [private] |
Service framework related initialization.
Definition at line 334 of file XMLAuthenticationService.cc.
References Debug, edm::endmsg(), create_public_lumi_plots::log, python::rootplot::argparse::message, valtools::processFile(), fetchall_from_DQM_v2::release, reset(), query::result, and AlCaHLTBitMon_QueryRunRegistry::string.
{ coral::MessageStream log("cond::XMLAuthenticationService::initialize"); std::set< std::string > inputFileNames = this->verifyFileName(); if ( inputFileNames.empty() ) { //seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); //std::cout<< "Could not open \"" << m_inputFileName << "\" for reading" << std::endl; log<<coral::Debug<<"Could not open \"" << m_inputFileName << "\" for reading" <<coral::MessageStream::endmsg; return false; } try { xercesc::XMLPlatformUtils::Initialize(); } catch ( const xercesc::XMLException& toCatch ) { char* message = xercesc::XMLString::transcode( toCatch.getMessage() ); //seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); //log << seal::Msg::Error << message << seal::flush; log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg; xercesc::XMLString::release( &message ); return false; } bool result = false; for ( std::set< std::string >::const_reverse_iterator iFileName = inputFileNames.rbegin(); iFileName != inputFileNames.rend(); ++iFileName ) { if ( this->processFile( *iFileName ) ) { result = true; } } xercesc::XMLPlatformUtils::Terminate(); m_isInitialized = result; if(!m_isInitialized) reset(); return result; }
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(), cont, cond::FileReader::content(), Debug, edm::endmsg(), analyzePatCOC_cfg::inputFile, create_public_lumi_plots::log, python::rootplot::argparse::message, mergeVDriftHistosByStation::name, geometryXMLtoCSV::parser, getHLTPrescaleColumns::path, cond::FileReader::read(), fetchall_from_DQM_v2::release, query::result, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().
{ coral::MessageStream log("cond::XMLAuthenticationService::processFile"); //std::cout<< "Processing file \""<< inputFileName<<"\"" <<std::endl; bool result = true; cond::FileReader inputFile; std::string cont(""); try{ inputFile.read(inputFileName); cont = inputFile.content(); } catch (const cond::Exception& exc){ log << coral::Error << "File \"" << inputFileName << "\" not found."<<std::string(exc.what())<<coral::MessageStream::endmsg; return false; } // check the boost::filesystem::path filePath( inputFileName ); #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47 std::string name = filePath.filename().string(); #else std::string name = filePath.leaf(); #endif xercesc::MemBufInputSource* memBufInputSource = 0; try { xercesc::XercesDOMParser parser; parser.setValidationScheme( xercesc::XercesDOMParser::Val_Always ); parser.setDoNamespaces( true ); xercesc::HandlerBase errorHandler; parser.setErrorHandler( &errorHandler ); const char* bufferId="InMemoryDocument"; const char* buffer = cont.c_str(); memBufInputSource = new xercesc::MemBufInputSource( (const XMLByte*)buffer,strlen(buffer),bufferId,false ); parser.parse(*memBufInputSource); xercesc::DOMDocument* document = parser.getDocument(); XMLCh tempStr[20]; xercesc::XMLString::transcode( "connection", tempStr, 19); xercesc::DOMNodeList* connectionList = document->getElementsByTagName( tempStr ); if ( connectionList ) { XMLSize_t numberOfConnections = connectionList->getLength(); for ( XMLSize_t iConnection = 0; iConnection < numberOfConnections; ++iConnection ) { xercesc::DOMNode* connectionNode = connectionList->item( iConnection ); if ( connectionNode ) { char* connectionName = xercesc::XMLString::transcode( connectionNode->getAttributes()->item( 0 )->getNodeValue() ); std::string sConnectionName = connectionName; xercesc::XMLString::release( &connectionName ); // Locate the credential cond::XMLAuthenticationService::DataSourceEntry* credential = 0; std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.find( sConnectionName ); if ( iConnection != m_data.end() ) { credential = iConnection->second; // Issue a warning here. //coral::MessageStream log( this, this->name(),seal::Msg::Verbose ); log<<coral::Debug<<"Credential parameters for connection string \"" << sConnectionName << "\" have already been defined. Only new elements are appended, while existing will be ignored." << coral::MessageStream::endmsg; } else { credential = new cond::XMLAuthenticationService::DataSourceEntry( this->name(), sConnectionName ); m_data.insert( std::make_pair( sConnectionName, credential ) ); } xercesc::DOMNodeList* parameterList = connectionNode->getChildNodes(); if ( parameterList ) { XMLSize_t numberOfParameters = parameterList->getLength(); for ( XMLSize_t iParameter = 0; iParameter < numberOfParameters; ++iParameter ) { xercesc::DOMNode* parameterNode = parameterList->item( iParameter ); if ( parameterNode && parameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { char* nodeName = xercesc::XMLString::transcode( parameterNode->getNodeName() ); std::string sNodeName = nodeName; xercesc::XMLString::release( &nodeName ); if ( sNodeName == "parameter" ) { // The default parameters char* parameterName = xercesc::XMLString::transcode( parameterNode->getAttributes()->item( 0 )->getNodeValue() ); std::string sParameterName = parameterName; xercesc::XMLString::release( ¶meterName ); char* parameterValue = xercesc::XMLString::transcode( parameterNode->getAttributes()->item( 1 )->getNodeValue() ); std::string sParameterValue = parameterValue; xercesc::XMLString::release( ¶meterValue ); credential->appendCredentialItem( sParameterName, sParameterValue ); } else if ( sNodeName == "role" ) { // A role char* roleName = xercesc::XMLString::transcode( parameterNode->getAttributes()->item( 0 )->getNodeValue() ); std::string sRoleName = roleName; xercesc::XMLString::release( &roleName ); // Retrieve the parameters for the role xercesc::DOMNodeList* roleParameterList = parameterNode->getChildNodes(); if ( roleParameterList ) { XMLSize_t numberOfRoleParameters = roleParameterList->getLength(); for ( XMLSize_t iRoleParameter = 0; iRoleParameter < numberOfRoleParameters; ++iRoleParameter ) { xercesc::DOMNode* roleParameterNode = roleParameterList->item( iRoleParameter ); if ( roleParameterNode && roleParameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { char* roleNodeName = xercesc::XMLString::transcode( roleParameterNode->getNodeName() ); std::string sRoleNodeName = roleNodeName; xercesc::XMLString::release( &roleNodeName ); if ( sRoleNodeName == "parameter" ) { char* roleParameterName = xercesc::XMLString::transcode( roleParameterNode->getAttributes()->item( 0 )->getNodeValue() ); std::string sRoleParameterName = roleParameterName; xercesc::XMLString::release( &roleParameterName ); char* roleParameterValue = xercesc::XMLString::transcode( roleParameterNode->getAttributes()->item( 1 )->getNodeValue() ); std::string sRoleParameterValue = roleParameterValue; xercesc::XMLString::release( &roleParameterValue ); credential->appendCredentialItemForRole( sRoleParameterName, sRoleParameterValue, sRoleName ); } } } } } } } } } } } parser.reset(); } catch ( const xercesc::XMLException& toCatch ) { char* message = xercesc::XMLString::transcode( toCatch.getMessage() ); //coral::MessageStream log( this, this->name(),coral::Msg::Verbose ); //log << coral::Msg::Error << message << coral::flush; log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg; xercesc::XMLString::release( &message ); result = false; } catch ( const xercesc::DOMException& toCatch ) { char* message = xercesc::XMLString::transcode( toCatch.msg ); //seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); //log << seal::Msg::Error << message << seal::flush; log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg; xercesc::XMLString::release( &message ); result = false; } catch ( const xercesc::SAXException& toCatch ) { char* message = xercesc::XMLString::transcode( toCatch.getMessage() ); //seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); //log << seal::Msg::Error << message << seal::flush; log<<coral::Error<<std::string(message)<<coral::MessageStream::endmsg; xercesc::XMLString::release( &message ); result = false; } catch (...){ //seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); //log << seal::Msg::Error << "Unexpected Exception parsing file \"" << inputFileName << "\"" << seal::flush; log<<coral::Error<<"Unexpected Exception parsing file \"" << inputFileName << "\"" <<coral::MessageStream::endmsg; result = false; } if(memBufInputSource) delete memBufInputSource; return result; }
void cond::XMLAuthenticationService::XMLAuthenticationService::reset | ( | void | ) | [private] |
Reset parsed data.
Definition at line 375 of file XMLAuthenticationService.cc.
{ for ( std::map< std::string, cond::XMLAuthenticationService::DataSourceEntry* >::iterator iConnection = m_data.begin(); iConnection != m_data.end(); ++iConnection ) delete iConnection->second; m_data.clear(); m_isInitialized = false; }
void cond::XMLAuthenticationService::XMLAuthenticationService::setAuthenticationPath | ( | const std::string & | inputPath | ) |
Sets the input file name.
Definition at line 112 of file XMLAuthenticationService.cc.
References getHLTPrescaleColumns::path, reset(), and XML_AUTHENTICATION_FILE.
Referenced by XMLAuthenticationService().
{ boost::filesystem::path boostAuthPath( inputPath ); if(boost::filesystem::is_directory(boostAuthPath)){ boostAuthPath /= boost::filesystem::path(XML_AUTHENTICATION_FILE); } m_inputFileName = boostAuthPath.string(); reset(); }
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, edm::endmsg(), LaserDQM_cfg::fileNames, create_public_lumi_plots::log, getHLTPrescaleColumns::path, and AlCaHLTBitMon_QueryRunRegistry::string.
{ coral::MessageStream log("cond::XMLAuthenticationService::verifyFileName"); std::set< std::string > fileNames; // Try the file name as is... boost::filesystem::path filePath( m_inputFileName ); if ( boost::filesystem::exists( m_inputFileName ) ) { if(boost::filesystem::is_directory( m_inputFileName )){ //seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log <<coral::Error << "Provided path \"" << m_inputFileName << "\" is a directory." <<coral::MessageStream::endmsg; return fileNames; } boost::filesystem::path& fullPath = filePath.normalize(); fileNames.insert( fullPath.string() ); if(filePath.is_complete()) return fileNames; } // Try to find other files in the path variable const char* thePathVariable = ::getenv( "CORAL_AUTH_PATH" ); if ( ! thePathVariable ) return fileNames; log<<coral::Debug<< "File \"" << m_inputFileName << "\" not found in the current directory. Trying in the search path." <<coral::MessageStream::endmsg; std::string searchPath(thePathVariable); //std::cout<<"searchPath "<<searchPath<<std::endl; if(boost::filesystem::exists(searchPath)){ if(!boost::filesystem::is_directory( searchPath )){ log<<coral::Debug<<"Search path \"" << searchPath << "\" is not a directory."<<coral::MessageStream::endmsg; return fileNames; } boost::filesystem::path fullPath( searchPath ); fullPath /= filePath; fileNames.insert( fullPath.string() ); } else { log<<coral::Debug<<"Search path \"" << searchPath << "\" does not exist."<<coral::MessageStream::endmsg; return fileNames; } return fileNames; }
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.
Flag indicating whether the service has been initialized.
Definition at line 129 of file XMLAuthenticationService.h.
boost::mutex cond::XMLAuthenticationService::XMLAuthenticationService::m_mutexLock [mutable, private] |
the mutex lock
Definition at line 138 of file XMLAuthenticationService.h.