CMS 3D CMS Logo

RelationalAuthenticationService.cc
Go to the documentation of this file.
3 #include "RelationalAccess/AuthenticationCredentials.h"
4 #include "RelationalAccess/AuthenticationServiceException.h"
7 //
8 #include "RelationalAccess/AuthenticationServiceException.h"
9 #include "CoralKernel/IPropertyManager.h"
10 #include "CoralKernel/Property.h"
11 #include "CoralKernel/Context.h"
12 //
13 #include <memory>
14 #include <cstdlib>
15 #include <fstream>
16 #include <sys/stat.h>
17 #include <fcntl.h>
18 #include <boost/filesystem.hpp>
19 #include <boost/version.hpp>
20 #include <boost/bind.hpp>
21 //#include <iostream>
22 #include "CoralBase/MessageStream.h"
23 
25  const std::string& key)
26  : coral::Service(key), m_authenticationPath(""), m_db(), m_cache(), m_callbackID(0) {
27  boost::function1<void, std::string> cb(boost::bind(
29 
30  coral::Property* pm = dynamic_cast<coral::Property*>(
31  coral::Context::instance().PropertyManager().property(auth::COND_AUTH_PATH_PROPERTY));
32  if (pm) {
33  setAuthenticationPath(pm->get());
34  m_callbackID = pm->registerCallback(cb);
35  }
36 }
37 
39 
41  const std::string& inputPath) {
43  m_cache.reset();
44 }
45 
46 const coral::IAuthenticationCredentials&
48  const std::string& connectionString) const {
49  const coral::IAuthenticationCredentials* creds = m_cache.get(connectionString);
50  if (!creds) {
51  std::string credsStoreConn = m_db.setUpForConnectionString(connectionString, m_authenticationPath);
52  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
53  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""
54  << m_db.keyPrincipalName() << "\"." << coral::MessageStream::endmsg;
56  }
57  creds = m_cache.get(connectionString);
58  if (!creds) {
59  std::string msg("Connection to \"");
60  msg += connectionString + "\"";
61  msg += " with role \"COND_DEFAULT_ROLE\" is not available for ";
62  msg += m_db.keyPrincipalName();
63  cond::throwException(msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials");
64  }
65  return *creds;
66 }
67 
68 const coral::IAuthenticationCredentials&
70  const std::string& role) const {
71  const coral::IAuthenticationCredentials* creds = m_cache.get(connectionString, role);
72  if (!creds) {
73  std::string credsStoreConn = m_db.setUpForConnectionString(connectionString, m_authenticationPath);
74  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
75  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""
76  << m_db.keyPrincipalName() << "\"." << coral::MessageStream::endmsg;
78  }
79  creds = m_cache.get(connectionString, role);
80  if (!creds) {
81  std::string msg("Connection to \"");
82  msg += connectionString + "\"";
83  msg += " with role \"" + role + "\" is not available for ";
84  msg += m_db.keyPrincipalName();
85  cond::throwException(msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials");
86  }
87  return *creds;
88 }
89 
91  "COND/Services/RelationalAuthenticationService");
const std::string & keyPrincipalName()
static PFTauRenderPlugin instance
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
#define DEFINE_CORALSERVICE(type, name)
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
std::string setUpForConnectionString(const std::string &connectionString, const std::string &authPath)
Definition: Binary.h:9
bool selectForUser(coral_bridge::AuthenticationCredentialSet &destinationData)
tuple msg
Definition: mps_check.py:285
const coral::IAuthenticationCredentials * get(const std::string &connectionString) const
CredentialStore m_db
The service providing the authentication data.
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const override
const bool Debug