Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef COND_XMLAUTHENTITACTIONSERVICE_H
0002 #define COND_XMLAUTHENTITACTIONSERVICE_H
0003 
0004 #include "RelationalAccess/IAuthenticationService.h"
0005 #include "CoralKernel/Service.h"
0006 #include "CoralKernel/Property.h"
0007 #include <map>
0008 #include <set>
0009 #include <string>
0010 #include <boost/thread.hpp>
0011 
0012 namespace coral {
0013 
0014   class AuthenticationCredentials;
0015   //class IAuthenticationCredentials;
0016 }  // namespace coral
0017 
0018 namespace cond {
0019 
0020   namespace XMLAuthenticationService {
0021 
0022     /**
0023      * @class DataSourceEntry
0024      *
0025      * A simple class holding the roles and the credentials corresponding to a database service
0026      */
0027     class DataSourceEntry {
0028     public:
0029       /// Constructor
0030       DataSourceEntry(const std::string& serviceName, const std::string& connectionName);
0031       DataSourceEntry() = delete;
0032       DataSourceEntry(const DataSourceEntry&) = delete;
0033       DataSourceEntry& operator=(const DataSourceEntry&) = delete;
0034 
0035       /// Destructor
0036       ~DataSourceEntry();
0037 
0038       /**
0039        * Adds a credential item to the default role.
0040        */
0041       void appendCredentialItem(const std::string& item, const std::string& value);
0042 
0043       /**
0044        * Adds a credential item to the default role.
0045        */
0046       void appendCredentialItemForRole(const std::string& item, const std::string& value, const std::string& role);
0047 
0048       /**
0049        * Returns a reference to the credentials object for the default role.
0050        */
0051       const coral::IAuthenticationCredentials& credentials() const;
0052 
0053       /**
0054        * Returns a reference to the credentials object for a given role.
0055        * If the role is not known to the service an UnknownRoleException is thrown.
0056        */
0057       const coral::IAuthenticationCredentials& credentials(const std::string& role) const;
0058 
0059     private:
0060       /// The service name
0061       std::string m_serviceName;
0062 
0063       /// The connection name
0064       std::string m_connectionName;
0065 
0066       /// The input file with the data
0067       coral::AuthenticationCredentials* m_default;
0068 
0069       /// The structure with the authentication data for the various roles
0070       std::map<std::string, coral::AuthenticationCredentials*> m_data;
0071     };
0072 
0073     /**
0074      * @class AuthenticationService AuthenticationService.h
0075      *
0076      * A simple implementation of the IAuthenticationService interface based on reading an XMl file
0077      */
0078     class XMLAuthenticationService : public coral::Service, virtual public coral::IAuthenticationService {
0079     public:
0080       /// Standard Constructor
0081       explicit XMLAuthenticationService(const std::string& name);
0082 
0083       /// Standard Destructor
0084       ~XMLAuthenticationService() override;
0085 
0086     public:
0087       /**
0088        * Returns a reference to the credentials object for a given connection string.
0089        * If the connection string is not known to the service an UnknownConnectionException is thrown.
0090        */
0091       const coral::IAuthenticationCredentials& credentials(const std::string& connectionString) const override;
0092 
0093       /**
0094        * Returns a reference to the credentials object for a given connection string.
0095        * If the connection string is not known to the service an UnknownConnectionException is thrown.
0096        * If the role is not known to the service an UnknownRoleException is thrown.
0097        */
0098       const coral::IAuthenticationCredentials& credentials(const std::string& connectionString,
0099                                                            const std::string& role) const override;
0100 
0101     public:
0102       /// Sets the input file name
0103       void setAuthenticationPath(const std::string& inputPath);
0104 
0105     private:
0106       /// Service framework related initialization
0107       bool initialize();
0108 
0109       /// Reset parsed data
0110       void reset();
0111 
0112       /// Parses an xml file
0113       bool processFile(const std::string& inputFileName);
0114 
0115       /// Verifies the existence of the authentication files
0116       std::set<std::string> verifyFileName();
0117 
0118       /// Flag indicating whether the service has been initialized
0119       bool m_isInitialized;
0120 
0121       /// The input file with the data
0122       std::string m_inputFileName;
0123 
0124       /// The structure with the authentication data
0125       std::map<std::string, DataSourceEntry*> m_data;
0126 
0127       /// the mutex lock
0128       mutable boost::mutex m_mutexLock;
0129 
0130       coral::Property::CallbackID m_callbackID;
0131     };
0132 
0133   }  // namespace XMLAuthenticationService
0134 
0135 }  // namespace cond
0136 
0137 #endif