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 <cstdlib>
14 #include <fcntl.h>
15 #include <fstream>
16 #include <memory>
17 #include <sys/stat.h>
18 
19 #include "CoralBase/MessageStream.h"
20 
22  const std::string& key)
23  : coral::Service(key), m_authenticationPath(""), m_db(), m_cache(), m_callbackID(0) {
24  boost::function1<void, std::string> cb(
26  this,
27  std::placeholders::_1));
28 
29  coral::Property* pm = dynamic_cast<coral::Property*>(
30  coral::Context::instance().PropertyManager().property(auth::COND_AUTH_PATH_PROPERTY));
31  if (pm) {
32  setAuthenticationPath(pm->get());
33  m_callbackID = pm->registerCallback(cb);
34  }
35 }
36 
38 
40  const std::string& inputPath) {
41  m_authenticationPath = inputPath;
42  m_cache.reset();
43 }
44 
45 const coral::IAuthenticationCredentials&
47  const std::string& connectionStr) const {
48  std::string connectionString = to_lower(connectionStr);
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;
55  m_db.selectForUser(m_cache);
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  std::string connectionString = to_lower(connectionStr);
72  const coral::IAuthenticationCredentials* creds = m_cache.get(connectionString, role);
73  if (!creds) {
74  std::string credsStoreConn = m_db.setUpForConnectionString(connectionString, m_authenticationPath);
75  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
76  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""
77  << m_db.keyPrincipalName() << "\"." << coral::MessageStream::endmsg;
78  m_db.selectForUser(m_cache);
79  }
80  creds = m_cache.get(connectionString, role);
81  if (!creds) {
82  std::string msg("Connection to \"");
83  msg += connectionString + "\"";
84  msg += " with role \"" + role + "\" is not available for ";
85  msg += m_db.keyPrincipalName();
86  cond::throwException(msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials");
87  }
88  return *creds;
89 }
90 
92  return m_db.keyPrincipalName();
93 }
94 
96  "COND/Services/RelationalAuthenticationService");
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const override
static PFTauRenderPlugin instance
std::string to_lower(const std::string &s)
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:50
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.
Definition: Binary.h:9
tuple msg
Definition: mps_check.py:286
const bool Debug