Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:51

0001 #include "CondCore/CondDB/interface/Auth.h"
0002 #include "CondCore/CondDB/interface/Exception.h"
0003 #include "CondCore/CondDB/interface/CredentialStore.h"
0004 #include "CondCore/Utilities/interface/Utilities.h"
0005 //
0006 #include "RelationalAccess/AuthenticationCredentials.h"
0007 #include "Utilities/Xerces/interface/Xerces.h"
0008 //
0009 #include <iostream>
0010 #include <fstream>
0011 #include <iomanip>
0012 
0013 namespace coral_bridge {
0014   bool parseXMLAuthenticationFile(const std::string& inputFileName, coral_bridge::AuthenticationCredentialSet& data);
0015 
0016   // class for creating the XML Authentication file
0017   class XMLAuthenticationFileContent {
0018   public:
0019     explicit XMLAuthenticationFileContent(std::ostream& out);
0020 
0021     bool openConnectionEntry(const std::string& pcs);
0022 
0023     bool closeConnectionEntry();
0024 
0025     bool openRoleEntry(const std::string& roleName);
0026 
0027     bool closeRoleEntry();
0028 
0029     bool addCredentialEntry(const std::string& userName, const std::string& password);
0030 
0031     void close();
0032 
0033   private:
0034     std::ostream& m_out;
0035 
0036     bool m_connectionListOpen;
0037 
0038     bool m_connectionEntryOpen;
0039 
0040     bool m_roleEntryOpen;
0041 
0042     unsigned int m_ind;
0043   };
0044 
0045 }  // namespace coral_bridge
0046 
0047 namespace cond {
0048   class AuthenticationManager : public Utilities {
0049   public:
0050     AuthenticationManager();
0051     ~AuthenticationManager() override;
0052     int execute() override;
0053   };
0054 }  // namespace cond
0055 
0056 cond::AuthenticationManager::AuthenticationManager() : Utilities("cmscond_authentication_manager") {
0057   addOption<std::string>("authPath", "P", "authentication path");
0058   addOption<bool>("create", "", "[-s a0 -u a1] create creds db");
0059   addOption<bool>("reset_admin", "", "[-s a0 -u a1] reset write credentials for admin");
0060   addOption<bool>("drop", "", "[-c a0 -u a1] drop creds db");
0061   addOption<bool>("update_princ", "", "[-s a0 -k a1 (-a)] add/update principal");
0062   addOption<bool>("update_conn", "", "[-s a0 -u a1 (-l a3)] add/update connection");
0063   addOption<bool>("set_perm", "", "[-s a0 -n a1 -r a2 -c a3 -l a4] set permission");
0064   addOption<bool>("unset_perm", "", "[-s a0 -n a1 -r a2 -c a3] unset permission");
0065   addOption<bool>("list_conn", "", "[-s arg ] list connections");
0066   addOption<bool>("list_perm", "", "[-s a0 (-n a1)(-r a2)(-c a3)] list permissions");
0067   addOption<bool>("list_princ", "", "[-s arg] list principals");
0068   addOption<bool>("remove_princ", "", "[-s a0 -n a1] remove principal");
0069   addOption<bool>("remove_conn", "", "[-s a0 -l a1] remove connection");
0070   addOption<bool>("admin", "a", "add admin privileges");
0071   addOption<bool>("force_update", "f", "force update");
0072   addOption<std::string>("import", "", "[a0 -s a1 -n a2 (-f)] import from the xml file");
0073   addOption<std::string>("export", "", "[a0 -s a1] export to the xml file");
0074   addOption<std::string>("service", "s", "service name");
0075   addOption<std::string>("princ_name", "n", "the principal");
0076   addOption<std::string>("key", "k", "the key filename");
0077   addOption<std::string>("role", "r", "the role");
0078   addOption<std::string>("connectionString", "c", "the connection string");
0079   addOption<std::string>("connectionLabel", "l", "the connection label");
0080   addOption<std::string>("userName", "u", "the user name");
0081 }
0082 
0083 cond::AuthenticationManager::~AuthenticationManager() {}
0084 
0085 int cond::AuthenticationManager::execute() {
0086   if (hasDebug())
0087     coral::MessageStream::setMsgVerbosity(coral::Debug);
0088   std::string authPath("");
0089   if (hasOptionValue("authPath"))
0090     authPath = getOptionValue<std::string>("authPath");
0091   if (authPath.empty()) {
0092     const char* authEnv = ::getenv(auth::COND_AUTH_PATH);
0093     if (authEnv) {
0094       authPath += authEnv;
0095     } else {
0096       authEnv = ::getenv("HOME");
0097       if (authEnv) {
0098         authPath += authEnv;
0099       }
0100     }
0101   }
0102 
0103   bool drop = hasOptionValue("drop");
0104   bool create = hasOptionValue("create");
0105   bool reset_admin = hasOptionValue("reset_admin");
0106   bool update_princ = hasOptionValue("update_princ");
0107   bool update_conn = hasOptionValue("update_conn");
0108   bool list_conn = hasOptionValue("list_conn");
0109   bool list_perm = hasOptionValue("list_perm");
0110   bool list_princ = hasOptionValue("list_princ");
0111   bool remove_princ = hasOptionValue("remove_princ");
0112   bool remove_conn = hasOptionValue("remove_conn");
0113   bool set_perm = hasOptionValue("set_perm");
0114   bool unset_perm = hasOptionValue("unset_perm");
0115   bool import = hasOptionValue("import");
0116   bool exp = hasOptionValue("export");
0117 
0118   bool not_exec = true;
0119   CredentialStore credDb;
0120 
0121   if (drop) {
0122     std::string connectionString = getOptionValue<std::string>("connectionString");
0123     std::string userName = getOptionValue<std::string>("userName");
0124     std::string password = cond::getpassForUser(userName);
0125     credDb.drop(connectionString, userName, password);
0126     std::cout << "Credential Repository in " << connectionString << " has been dropped." << std::endl;
0127     not_exec = false;
0128   }
0129 
0130   std::string service("");
0131   if (create && not_exec) {
0132     service = getOptionValue<std::string>("service");
0133     std::string userName = getOptionValue<std::string>("userName");
0134     std::string password = cond::getpassForUser(userName);
0135     std::string credsStore = credDb.setUpForService(service, authPath);
0136     credDb.createSchema(credsStore, userName, password);
0137     std::cout << "Credential Repository for service " << service << " has been created." << std::endl;
0138     not_exec = false;
0139   }
0140 
0141   if (reset_admin || update_princ || update_conn || remove_princ || remove_conn || set_perm || unset_perm || import ||
0142       list_conn || list_princ || list_perm || exp) {
0143     service = getOptionValue<std::string>("service");
0144     std::string credsStore = credDb.setUpForService(service, authPath);
0145     std::cout << "Authenticated principal " << credDb.keyPrincipalName() << std::endl;
0146     std::cout << "Connecting with credential repository in \"" << credsStore << "\"" << std::endl;
0147   }
0148 
0149   if (reset_admin && not_exec) {
0150     std::string userName = getOptionValue<std::string>("userName");
0151     std::string password = cond::getpassForUser(userName);
0152     credDb.resetAdmin(userName, password);
0153     std::cout << "Admin access to service " << credDb.serviceName() << " has been reset." << std::endl;
0154     not_exec = false;
0155   }
0156 
0157   if (update_princ && not_exec) {
0158     bool adminOpt = hasOptionValue("admin");
0159     std::string key = getOptionValue<std::string>("key");
0160     auth::DecodingKey pk;
0161     pk.init(key, auth::COND_KEY);
0162     credDb.updatePrincipal(pk.principalName(), pk.principalKey(), adminOpt);
0163     std::cout << "Principal " << pk.principalName() << " has been updated." << std::endl;
0164     not_exec = false;
0165   }
0166 
0167   if (update_conn && not_exec) {
0168     std::string userName = getOptionValue<std::string>("userName");
0169     std::string password = cond::getpassForUser(userName);
0170     std::string connectionLabel = schemaLabel(service, userName);
0171     if (hasOptionValue("connectionLabel")) {
0172       connectionLabel = getOptionValue<std::string>("connectionLabel");
0173     }
0174     credDb.updateConnection(connectionLabel, userName, password);
0175     std::cout << "Credentials for connection " << connectionLabel << " have been updated." << std::endl;
0176     not_exec = false;
0177   }
0178 
0179   if (remove_princ && not_exec) {
0180     std::string principal = getOptionValue<std::string>("princ_name");
0181     credDb.removePrincipal(principal);
0182     std::cout << "Principal " << principal << " has been removed." << std::endl;
0183     not_exec = false;
0184   }
0185 
0186   if (remove_conn && not_exec) {
0187     std::string connectionLabel = getOptionValue<std::string>("connectionLabel");
0188     credDb.removeConnection(connectionLabel);
0189     std::cout << "Connection " << connectionLabel << " has been removed." << std::endl;
0190     not_exec = false;
0191   }
0192 
0193   if (set_perm && not_exec) {
0194     std::string principal = getOptionValue<std::string>("princ_name");
0195     std::string role = getOptionValue<std::string>("role");
0196     std::string connectionString = getOptionValue<std::string>("connectionString");
0197     std::string connectionLabel = getOptionValue<std::string>("connectionLabel");
0198     credDb.setPermission(principal, role, connectionString, connectionLabel);
0199     std::cout << "Permission for principal " << principal << " to access resource " << connectionString << " with role "
0200               << role << " has been set." << std::endl;
0201     not_exec = false;
0202   }
0203 
0204   if (unset_perm && not_exec) {
0205     std::string connectionString = getOptionValue<std::string>("connectionString");
0206     std::string principal("");
0207     if (hasOptionValue("princ_name"))
0208       principal = getOptionValue<std::string>("princ_name");
0209     std::string role("");
0210     if (hasOptionValue("role"))
0211       role = getOptionValue<std::string>("role");
0212     size_t n = credDb.unsetPermission(principal, role, connectionString);
0213     if (n) {
0214       std::cout << n << " permissions to access resource " << connectionString;
0215       if (!role.empty())
0216         std::cout << " with role " << role;
0217       std::cout << " have been unset";
0218       if (!principal.empty())
0219         std::cout << " for principal " << principal << " ";
0220     } else {
0221       std::cout << "No Permission found to access resource " << connectionString;
0222       if (!role.empty())
0223         std::cout << " with role " << role;
0224       if (!principal.empty())
0225         std::cout << " for principal " << principal << " ";
0226     }
0227     std::cout << "." << std::endl;
0228     not_exec = false;
0229   }
0230 
0231   if (import && not_exec) {
0232     bool forceUp = hasOptionValue("force_update");
0233     std::string fileName = getOptionValue<std::string>("import");
0234     std::string principal = getOptionValue<std::string>("princ_name");
0235     coral_bridge::AuthenticationCredentialSet source;
0236     if (!coral_bridge::parseXMLAuthenticationFile(fileName, source)) {
0237       std::cout << "Error: XML parsing failed." << std::endl;
0238       return 1;
0239     }
0240     std::cout << "Importing " << source.data().size() << " connection items." << std::endl;
0241     credDb.importForPrincipal(principal, source, forceUp);
0242     std::cout << "Credential set for principal " << principal << " has been imported from file " << fileName
0243               << std::endl;
0244     not_exec = false;
0245   }
0246 
0247   if (list_conn && not_exec) {
0248     std::map<std::string, std::pair<std::string, std::string> > data;
0249     credDb.listConnections(data);
0250     std::cout << "Found " << data.size() << " connection(s)." << std::endl;
0251     std::cout << std::endl;
0252     static std::string connectionLabelH("connection label");
0253     static std::string userNameH("username");
0254     static std::string passwordH("password");
0255     size_t connectionLabelW = connectionLabelH.size();
0256     size_t userNameW = 0;
0257     size_t passwordW = 0;
0258     for (std::map<std::string, std::pair<std::string, std::string> >::const_iterator iC = data.begin();
0259          iC != data.end();
0260          ++iC) {
0261       const std::string& userName = iC->second.first;
0262       const std::string& password = iC->second.second;
0263       const std::string& connectionLabel = iC->first;
0264       if (connectionLabelW < connectionLabel.size())
0265         connectionLabelW = connectionLabel.size();
0266       if (userNameW < userName.size())
0267         userNameW = userName.size();
0268       if (passwordW < password.size())
0269         passwordW = password.size();
0270     }
0271     if (userNameW > 0 && userNameW < userNameH.size())
0272       userNameW = userNameH.size();
0273     if (passwordW > 0 && passwordW < passwordH.size())
0274       passwordW = passwordH.size();
0275     std::cout << std::setiosflags(std::ios_base::left);
0276     std::cout << std::setw(connectionLabelW) << connectionLabelH;
0277     if (userNameW) {
0278       std::cout << "  " << std::setw(userNameW) << userNameH;
0279     }
0280     if (passwordW) {
0281       std::cout << "  " << std::setw(passwordW) << passwordH;
0282     }
0283     std::cout << std::endl;
0284     std::cout << std::setfill('-');
0285     std::cout << std::setw(connectionLabelW) << "";
0286     if (userNameW) {
0287       std::cout << "  " << std::setw(userNameW) << "";
0288     }
0289     if (passwordW) {
0290       std::cout << "  " << std::setw(passwordW) << "";
0291     }
0292     std::cout << std::endl;
0293     std::cout << std::setfill(' ');
0294     for (std::map<std::string, std::pair<std::string, std::string> >::const_iterator iC = data.begin();
0295          iC != data.end();
0296          ++iC) {
0297       const std::string& connectionLabel = iC->first;
0298       const std::string& userName = iC->second.first;
0299       const std::string& password = iC->second.second;
0300       std::cout << std::setw(connectionLabelW) << connectionLabel << "  " << std::setw(userNameW) << userName << "  "
0301                 << std::setw(passwordW) << password << std::endl;
0302     }
0303     not_exec = false;
0304   }
0305 
0306   if (list_princ && not_exec) {
0307     std::vector<std::string> data;
0308     credDb.listPrincipals(data);
0309     std::cout << "Found " << data.size() << " principal(s)." << std::endl;
0310     std::cout << std::endl;
0311     static std::string principalH("principal name");
0312     size_t principalW = principalH.size();
0313     for (std::vector<std::string>::const_iterator iP = data.begin(); iP != data.end(); ++iP) {
0314       const std::string& principal = *iP;
0315       if (principalW < principal.size())
0316         principalW = principal.size();
0317     }
0318     std::cout << std::setiosflags(std::ios_base::left);
0319     std::cout << std::setw(principalW) << principalH << std::endl;
0320     std::cout << std::setfill('-');
0321     std::cout << std::setw(principalW) << "" << std::endl;
0322     std::cout << std::setfill(' ');
0323     for (std::vector<std::string>::const_iterator iP = data.begin(); iP != data.end(); ++iP) {
0324       std::cout << std::setw(principalW) << *iP << std::endl;
0325     }
0326     not_exec = false;
0327   }
0328 
0329   if (list_perm && not_exec) {
0330     std::vector<CredentialStore::Permission> data;
0331     std::string pName("");
0332     std::string role("");
0333     std::string conn("");
0334     if (hasOptionValue("connectionString"))
0335       conn = getOptionValue<std::string>("connectionString");
0336     if (hasOptionValue("princ_name"))
0337       pName = getOptionValue<std::string>("princ_name");
0338     if (hasOptionValue("role"))
0339       role = getOptionValue<std::string>("role");
0340     credDb.selectPermissions(pName, role, conn, data);
0341     std::cout << "Found " << data.size() << " permission(s)." << std::endl;
0342     std::cout << std::endl;
0343     static std::string connectionStringH("connection string");
0344     static std::string principalH("principal name");
0345     static std::string roleH("role");
0346     static std::string connectionLabelH("connection label");
0347     size_t connectionStringW = connectionStringH.size();
0348     size_t principalW = principalH.size();
0349     size_t roleW = roleH.size();
0350     size_t connectionLabelW = connectionLabelH.size();
0351     for (std::vector<CredentialStore::Permission>::const_iterator iP = data.begin(); iP != data.end(); ++iP) {
0352       const std::string& connectionString = iP->connectionString;
0353       if (connectionStringW < connectionString.size())
0354         connectionStringW = connectionString.size();
0355       const std::string& principal = iP->principalName;
0356       if (principalW < principal.size())
0357         principalW = principal.size();
0358       const std::string& role = iP->role;
0359       if (roleW < role.size())
0360         roleW = role.size();
0361       const std::string& connectionLabel = iP->connectionLabel;
0362       if (connectionLabelW < connectionLabel.size())
0363         connectionLabelW = connectionLabel.size();
0364     }
0365     std::cout << std::setiosflags(std::ios_base::left);
0366     std::cout << std::setw(connectionStringW) << connectionStringH << "  " << std::setw(principalW) << principalH
0367               << "  ";
0368     std::cout << std::setw(roleW) << roleH << "  " << std::setw(connectionLabelW) << connectionLabelH << std::endl;
0369     std::cout << std::setfill('-');
0370     std::cout << std::setw(connectionStringW) << ""
0371               << "  " << std::setw(principalW) << ""
0372               << "  " << std::setw(roleW) << ""
0373               << "  " << std::setw(connectionLabelW) << "" << std::endl;
0374     std::cout << std::setfill(' ');
0375     for (std::vector<CredentialStore::Permission>::const_iterator iP = data.begin(); iP != data.end(); ++iP) {
0376       std::cout << std::setw(connectionStringW) << iP->connectionString << "  " << std::setw(principalW)
0377                 << iP->principalName << "  ";
0378       ;
0379       std::cout << std::setw(roleW) << iP->role << "  " << std::setw(connectionLabelW) << iP->connectionLabel
0380                 << std::endl;
0381     }
0382     not_exec = false;
0383   }
0384 
0385   if (exp && not_exec) {
0386     std::string fileName = getOptionValue<std::string>("export");
0387     coral_bridge::AuthenticationCredentialSet data;
0388     credDb.exportAll(data);
0389     std::ofstream outFile(fileName);
0390     coral_bridge::XMLAuthenticationFileContent xmlFile(outFile);
0391     const std::map<std::pair<std::string, std::string>, coral::AuthenticationCredentials*>& creds = data.data();
0392     std::set<std::string> connections;
0393     bool started = false;
0394     for (std::map<std::pair<std::string, std::string>, coral::AuthenticationCredentials*>::const_iterator iEntry =
0395              creds.begin();
0396          iEntry != creds.end();
0397          iEntry++) {
0398       const std::string& connectStr = iEntry->first.first;
0399       std::set<std::string>::iterator iConn = connections.find(connectStr);
0400       if (iConn == connections.end()) {
0401         if (started)
0402           xmlFile.closeConnectionEntry();
0403         xmlFile.openConnectionEntry(connectStr);
0404         started = true;
0405         connections.insert(connectStr);
0406         std::pair<std::string, std::string> defRoleKey(connectStr, auth::COND_DEFAULT_ROLE);
0407         std::map<std::pair<std::string, std::string>, coral::AuthenticationCredentials*>::const_iterator iDef =
0408             creds.find(defRoleKey);
0409         if (iDef != creds.end()) {
0410           xmlFile.addCredentialEntry(iDef->second->valueForItem(coral::IAuthenticationCredentials::userItem()),
0411                                      iDef->second->valueForItem(coral::IAuthenticationCredentials::passwordItem()));
0412         }
0413       }
0414       const std::string& role = iEntry->first.second;
0415       if (role != auth::COND_DEFAULT_ROLE) {
0416         xmlFile.openRoleEntry(role);
0417         xmlFile.addCredentialEntry(iEntry->second->valueForItem(coral::IAuthenticationCredentials::userItem()),
0418                                    iEntry->second->valueForItem(coral::IAuthenticationCredentials::passwordItem()));
0419         xmlFile.closeRoleEntry();
0420       }
0421     }
0422     xmlFile.close();
0423     not_exec = false;
0424   }
0425 
0426   if (not_exec) {
0427     std::cout << "ERROR: no command specified." << std::endl;
0428     return 1;
0429   }
0430   if (hasDebug()) {
0431     std::cout << "LOGS from the Credential Store:" << std::endl;
0432     std::cout << credDb.log() << std::endl;
0433   }
0434   return 0;
0435 }
0436 
0437 int main(int argc, char** argv) {
0438   cond::AuthenticationManager mgr;
0439   return mgr.run(argc, argv);
0440 }
0441 
0442 #include "xercesc/parsers/XercesDOMParser.hpp"
0443 #include "xercesc/dom/DOM.hpp"
0444 #include "xercesc/sax/HandlerBase.hpp"
0445 #include "xercesc/util/XMLString.hpp"
0446 #include "xercesc/util/PlatformUtils.hpp"
0447 
0448 #if defined __SUNPRO_CC
0449 #pragma enable_warn
0450 #elif defined _MSC_VER
0451 #pragma warning(pop)
0452 #endif
0453 
0454 bool coral_bridge::parseXMLAuthenticationFile(const std::string& inputFileName, AuthenticationCredentialSet& data) {
0455   try {
0456     cms::concurrency::xercesInitialize();
0457   } catch (const xercesc::XMLException& toCatch) {
0458     char* message = xercesc::XMLString::transcode(toCatch.getMessage());
0459     //coral::MessageStream log( serviceName );
0460     //log << coral::Error << message << coral::MessageStream::endmsg;
0461     xercesc::XMLString::release(&message);
0462     return false;
0463   }
0464 
0465   bool result = true;
0466   try {
0467     xercesc::XercesDOMParser parser;
0468     parser.setValidationScheme(xercesc::XercesDOMParser::Val_Always);
0469     parser.setDoNamespaces(true);
0470 
0471     xercesc::HandlerBase errorHandler;
0472     parser.setErrorHandler(&errorHandler);
0473 
0474     parser.parse(inputFileName.c_str());
0475 
0476     xercesc::DOMDocument* document = parser.getDocument();
0477 
0478     XMLCh tempStr[20];
0479     xercesc::XMLString::transcode("connection", tempStr, 19);
0480 
0481     xercesc::DOMNodeList* connectionList = document->getElementsByTagName(tempStr);
0482 
0483     if (connectionList) {
0484       XMLSize_t numberOfConnections = connectionList->getLength();
0485 
0486       for (XMLSize_t iConnection = 0; iConnection < numberOfConnections; ++iConnection) {
0487         xercesc::DOMNode* connectionNode = connectionList->item(iConnection);
0488 
0489         if (connectionNode) {
0490           char* connectionName =
0491               xercesc::XMLString::transcode(connectionNode->getAttributes()->item(0)->getNodeValue());
0492           std::string sConnectionName = connectionName;
0493           xercesc::XMLString::release(&connectionName);
0494 
0495           xercesc::DOMNodeList* parameterList = connectionNode->getChildNodes();
0496 
0497           if (parameterList) {
0498             XMLSize_t numberOfParameters = parameterList->getLength();
0499 
0500             for (XMLSize_t iParameter = 0; iParameter < numberOfParameters; ++iParameter) {
0501               xercesc::DOMNode* parameterNode = parameterList->item(iParameter);
0502 
0503               if (parameterNode && parameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) {
0504                 char* nodeName = xercesc::XMLString::transcode(parameterNode->getNodeName());
0505                 std::string sNodeName = nodeName;
0506                 xercesc::XMLString::release(&nodeName);
0507 
0508                 if (sNodeName == "parameter") {  // The default parameters
0509                   char* parameterName =
0510                       xercesc::XMLString::transcode(parameterNode->getAttributes()->item(0)->getNodeValue());
0511                   std::string sParameterName = parameterName;
0512                   xercesc::XMLString::release(&parameterName);
0513                   char* parameterValue =
0514                       xercesc::XMLString::transcode(parameterNode->getAttributes()->item(1)->getNodeValue());
0515                   std::string sParameterValue = parameterValue;
0516                   xercesc::XMLString::release(&parameterValue);
0517 
0518                   data.registerItem(sConnectionName, sParameterName, sParameterValue);
0519                 } else if (sNodeName == "role") {  // A role
0520                   char* roleName =
0521                       xercesc::XMLString::transcode(parameterNode->getAttributes()->item(0)->getNodeValue());
0522                   std::string sRoleName = roleName;
0523                   xercesc::XMLString::release(&roleName);
0524 
0525                   // Retrieve the parameters for the role
0526                   xercesc::DOMNodeList* roleParameterList = parameterNode->getChildNodes();
0527 
0528                   if (roleParameterList) {
0529                     XMLSize_t numberOfRoleParameters = roleParameterList->getLength();
0530 
0531                     for (XMLSize_t iRoleParameter = 0; iRoleParameter < numberOfRoleParameters; ++iRoleParameter) {
0532                       xercesc::DOMNode* roleParameterNode = roleParameterList->item(iRoleParameter);
0533                       if (roleParameterNode && roleParameterNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) {
0534                         char* roleNodeName = xercesc::XMLString::transcode(roleParameterNode->getNodeName());
0535                         std::string sRoleNodeName = roleNodeName;
0536                         xercesc::XMLString::release(&roleNodeName);
0537 
0538                         if (sRoleNodeName == "parameter") {
0539                           char* roleParameterName = xercesc::XMLString::transcode(
0540                               roleParameterNode->getAttributes()->item(0)->getNodeValue());
0541                           std::string sRoleParameterName = roleParameterName;
0542                           xercesc::XMLString::release(&roleParameterName);
0543                           char* roleParameterValue = xercesc::XMLString::transcode(
0544                               roleParameterNode->getAttributes()->item(1)->getNodeValue());
0545                           std::string sRoleParameterValue = roleParameterValue;
0546                           xercesc::XMLString::release(&roleParameterValue);
0547 
0548                           data.registerItem(sConnectionName, sRoleName, sRoleParameterName, sRoleParameterValue);
0549                         }
0550                       }
0551                     }
0552                   }
0553                 }
0554               }
0555             }
0556           }
0557         }
0558       }
0559     }
0560 
0561     parser.reset();
0562   } catch (const xercesc::XMLException& toCatch) {
0563     char* message = xercesc::XMLString::transcode(toCatch.getMessage());
0564     //coral::MessageStream log( serviceName );
0565     //log << coral::Error << message << coral::MessageStream::endmsg;
0566     xercesc::XMLString::release(&message);
0567     result = false;
0568   } catch (const xercesc::DOMException& toCatch) {
0569     char* message = xercesc::XMLString::transcode(toCatch.msg);
0570     //coral::MessageStream log( serviceName );
0571     //log << coral::Error << message << coral::MessageStream::endmsg;
0572     xercesc::XMLString::release(&message);
0573     result = false;
0574   } catch (...) {
0575     //coral::MessageStream log( serviceName );
0576     //log << coral::Error << "Unexpected Exception parsing file \"" << inputFileName << "\"" << coral::MessageStream::endmsg;
0577     result = false;
0578   }
0579 
0580   cms::concurrency::xercesTerminate();
0581 
0582   return result;
0583 }
0584 
0585 #include "RelationalAccess/IAuthenticationCredentials.h"
0586 #include <iomanip>
0587 
0588 coral_bridge::XMLAuthenticationFileContent::XMLAuthenticationFileContent(std::ostream& out)
0589     : m_out(out), m_connectionListOpen(false), m_connectionEntryOpen(false), m_roleEntryOpen(false), m_ind(0) {
0590   m_out << "<?xml version=\"1.0\" ?>" << std::endl;
0591   m_out << "<connectionlist>" << std::endl;
0592   m_connectionListOpen = true;
0593 }
0594 
0595 bool coral_bridge::XMLAuthenticationFileContent::openConnectionEntry(const std::string& pcs) {
0596   bool ret = false;
0597   if (m_connectionListOpen && !m_connectionEntryOpen) {
0598     m_out << std::endl;
0599     m_ind += 2;
0600     m_out << std::setw(m_ind) << "";
0601     m_out << "<connection name=\"" << pcs << "\" >" << std::endl;
0602     m_connectionEntryOpen = true;
0603     ret = true;
0604   }
0605   return ret;
0606 }
0607 
0608 bool coral_bridge::XMLAuthenticationFileContent::closeConnectionEntry() {
0609   bool ret = false;
0610   if (m_connectionEntryOpen) {
0611     m_out << std::setw(m_ind) << "";
0612     m_out << "</connection>" << std::endl;
0613     m_ind -= 2;
0614     ret = true;
0615     m_connectionEntryOpen = false;
0616   }
0617   return ret;
0618 }
0619 
0620 bool coral_bridge::XMLAuthenticationFileContent::openRoleEntry(const std::string& roleName) {
0621   bool ret = false;
0622   if (m_connectionEntryOpen && !m_roleEntryOpen) {
0623     m_ind += 2;
0624     m_out << std::setw(m_ind) << "";
0625     m_out << "<role name=\"" << roleName << "\" >" << std::endl;
0626     m_roleEntryOpen = true;
0627     ret = true;
0628   }
0629   return ret;
0630 }
0631 
0632 bool coral_bridge::XMLAuthenticationFileContent::closeRoleEntry() {
0633   bool ret = false;
0634   if (m_roleEntryOpen) {
0635     m_out << std::setw(m_ind) << "";
0636     m_out << "</role>" << std::endl;
0637     m_ind -= 2;
0638     ret = true;
0639     m_roleEntryOpen = false;
0640   }
0641   return ret;
0642 }
0643 
0644 bool coral_bridge::XMLAuthenticationFileContent::addCredentialEntry(const std::string& userName,
0645                                                                     const std::string& password) {
0646   bool ret = false;
0647   if (m_connectionEntryOpen) {
0648     m_out << std::setw(m_ind + 2) << "";
0649     m_out << "<parameter name=\"" << coral::IAuthenticationCredentials::userItem() << "\" value=\"" << userName
0650           << "\" />" << std::endl;
0651     m_out << std::setw(m_ind + 2) << "";
0652     m_out << "<parameter name=\"" << coral::IAuthenticationCredentials::passwordItem() << "\" value=\"" << password
0653           << "\" />" << std::endl;
0654     ret = true;
0655   }
0656   return ret;
0657 }
0658 
0659 void coral_bridge::XMLAuthenticationFileContent::close() {
0660   if (m_connectionListOpen) {
0661     if (m_connectionEntryOpen) {
0662       if (m_roleEntryOpen) {
0663         closeRoleEntry();
0664       }
0665       closeConnectionEntry();
0666     }
0667     m_out << std::endl;
0668     m_out << "</connectionlist>" << std::endl;
0669   }
0670   m_connectionListOpen = false;
0671 }