00001 #ifndef INCLUDE_COND_CREDENTIALSTORE_H
00002 #define INCLUDE_COND_CREDENTAILSTORE_H
00003
00004 #include "CondCore/DBCommon/interface/DecodingKey.h"
00005
00006 #include <map>
00007 #include <string>
00008
00009 #include <boost/shared_ptr.hpp>
00010
00011
00012 namespace coral {
00013
00014 class AuthenticationCredentials;
00015 class IAuthenticationCredentials;
00016 class ISession;
00017 class IConnection;
00018
00019 }
00020
00021 namespace coral_bridge {
00022
00023 class AuthenticationCredentialSet {
00024
00025 public:
00027 AuthenticationCredentialSet();
00028
00030 virtual ~AuthenticationCredentialSet();
00031
00032
00033 void registerItem( const std::string& connectionString,
00034 const std::string& itemName,
00035 const std::string& itemValue );
00036
00037
00038 void registerItem( const std::string& connectionString,
00039 const std::string& role,
00040 const std::string& itemName,
00041 const std::string& itemValue );
00042
00046 void registerCredentials( const std::string& connectionString,
00047 const std::string& userName,
00048 const std::string& password );
00049
00053 void registerCredentials( const std::string& connectionString,
00054 const std::string& role,
00055 const std::string& userName,
00056 const std::string& password );
00057
00058 void import( const AuthenticationCredentialSet& data );
00059
00060 const coral::IAuthenticationCredentials* get( const std::string& connectionString ) const;
00061
00062 const coral::IAuthenticationCredentials* get( const std::string& connectionString, const std::string& role ) const;
00063
00064 const std::map< std::pair<std::string,std::string>, coral::AuthenticationCredentials* >& data() const ;
00065
00066 void reset();
00067
00068 private:
00070 std::map< std::pair<std::string,std::string>, coral::AuthenticationCredentials* > m_data;
00071
00072 };
00073
00074 }
00075
00076 namespace cond {
00077
00078 class Cipher;
00079
00080 std::string schemaLabel( const std::string& serviceName, const std::string& userName );
00081
00082
00083 class CredentialStore {
00084
00085 public:
00086
00087 static const std::string DEFAULT_DATA_SOURCE;
00088
00089 public:
00091 CredentialStore();
00092
00094 virtual ~CredentialStore();
00095
00096 public:
00097
00099 std::string setUpForService( const std::string& serviceName, const std::string& authPath );
00100
00101 std::string setUpForConnectionString( const std::string& connectionString, const std::string& authPath );
00102
00103 bool createSchema( const std::string& connectionString, const std::string& userName, const std::string& password );
00104
00105 bool drop( const std::string& connectionString, const std::string& userName, const std::string& password );
00106
00107 bool installAdmin( const std::string& userName, const std::string& password );
00108
00109 bool updatePrincipal( const std::string& principal, const std::string& principalKey, bool setAdmin=false);
00110
00111 bool setPermission( const std::string& principal, const std::string& role, const std::string& connectionString, const std::string& connectionLabel );
00112
00113 bool unsetPermission( const std::string& principal, const std::string& role, const std::string& connectionString );
00114
00115 bool updateConnection( const std::string& connectionLabel, const std::string& userName, const std::string& password );
00116
00117 bool removePrincipal( const std::string& principal );
00118
00119 bool removeConnection( const std::string& connectionLabel );
00120
00121 bool selectForUser( coral_bridge::AuthenticationCredentialSet& destinationData );
00122
00124 bool importForPrincipal( const std::string& principal, const coral_bridge::AuthenticationCredentialSet& data, bool forceUpdateConnection=false );
00125
00126 bool listPrincipals( std::vector<std::string>& destination );
00127
00128 bool listConnections( std::map<std::string,std::pair<std::string,std::string> >& destination );
00129
00130 struct Permission {
00131 std::string principalName;
00132 std::string role;
00133 std::string connectionString;
00134 std::string connectionLabel;
00135 };
00136 bool selectPermissions( const std::string& principalName, const std::string& role, const std::string& connectionString, std::vector<Permission>& destination );
00137
00138 bool exportAll( coral_bridge::AuthenticationCredentialSet& data );
00139
00140 const std::string& keyPrincipalName ();
00141
00142 private:
00143
00144 friend class CSScopedSession;
00145
00146 std::pair<std::string,std::string> openConnection( const std::string& connectionString );
00147 void openSession( const std::string& schemaName, const std::string& userName, const std::string& password, bool readMode );
00148 void startSuperSession( const std::string& connectionString, const std::string& userName, const std::string& password );
00149 void startSession( bool readMode );
00150
00151 void openSession( bool readOnly=true );
00152
00153 void closeSession( bool commit=true );
00154
00155 int addUser( const std::string& principalName, const std::string& authenticationKey, const std::string& principalKey, const std::string& adminKey );
00156
00157 bool setPermission( int principalId, const std::string& principalKey, const std::string& role, const std::string& connectionString, int connectionId, const std::string& connectionKey );
00158
00159 std::pair<int,std::string> updateConnection( const std::string& connectionLabel, const std::string& userName, const std::string& password, bool forceUpdate );
00160
00161 private:
00162
00163 boost::shared_ptr<coral::IConnection> m_connection;
00164 boost::shared_ptr<coral::ISession> m_session;
00165
00166 int m_principalId;
00167 std::string m_principalKey;
00168
00169 std::string m_serviceName;
00170 const ServiceCredentials* m_serviceData;
00171
00172 DecodingKey m_key;
00173
00174 };
00175
00176 }
00177
00178
00179
00180
00181 #endif