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 <boost/bind.hpp>
20 
21 #include "CoralBase/MessageStream.h"
22 
24  const std::string& key)
25  : coral::Service(key), m_authenticationPath(""), m_db(), m_cache(), m_callbackID(0) {
26  boost::function1<void, std::string> cb(boost::bind(
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& connectionString) const {
48  const coral::IAuthenticationCredentials* creds = m_cache.get(connectionString);
49  if (!creds) {
50  std::string credsStoreConn = m_db.setUpForConnectionString(connectionString, m_authenticationPath);
51  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
52  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""
53  << m_db.keyPrincipalName() << "\"." << coral::MessageStream::endmsg;
54  m_db.selectForUser(m_cache);
55  }
56  creds = m_cache.get(connectionString);
57  if (!creds) {
58  std::string msg("Connection to \"");
59  msg += connectionString + "\"";
60  msg += " with role \"COND_DEFAULT_ROLE\" is not available for ";
61  msg += m_db.keyPrincipalName();
62  cond::throwException(msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials");
63  }
64  return *creds;
65 }
66 
67 const coral::IAuthenticationCredentials&
69  const std::string& role) const {
70  const coral::IAuthenticationCredentials* creds = m_cache.get(connectionString, role);
71  if (!creds) {
72  std::string credsStoreConn = m_db.setUpForConnectionString(connectionString, m_authenticationPath);
73  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
74  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""
75  << m_db.keyPrincipalName() << "\"." << coral::MessageStream::endmsg;
76  m_db.selectForUser(m_cache);
77  }
78  creds = m_cache.get(connectionString, role);
79  if (!creds) {
80  std::string msg("Connection to \"");
81  msg += connectionString + "\"";
82  msg += " with role \"" + role + "\" is not available for ";
83  msg += m_db.keyPrincipalName();
84  cond::throwException(msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials");
85  }
86  return *creds;
87 }
88 
90  return m_db.keyPrincipalName();
91 }
92 
94  "COND/Services/RelationalAuthenticationService");
cond::RelationalAuthenticationService::RelationalAuthenticationService::setAuthenticationPath
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
Definition: RelationalAuthenticationService.cc:39
Exception.h
mps_check.msg
tuple msg
Definition: mps_check.py:285
cond::RelationalAuthenticationService::RelationalAuthenticationService::m_callbackID
coral::Property::CallbackID m_callbackID
Definition: RelationalAuthenticationService.h:66
Debug
const bool Debug
Definition: CosmicMuonParameters.h:12
RelationalAuthenticationService.h
coral
Definition: Binary.h:9
cond::RelationalAuthenticationService::RelationalAuthenticationService::RelationalAuthenticationService
RelationalAuthenticationService(const std::string &name)
Standard Constructor.
Definition: RelationalAuthenticationService.cc:23
CoralServiceMacros.h
Service
cond::RelationalAuthenticationService::RelationalAuthenticationService::~RelationalAuthenticationService
~RelationalAuthenticationService() override
Standard Destructor.
Definition: RelationalAuthenticationService.cc:37
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::RelationalAuthenticationService::RelationalAuthenticationService
Definition: RelationalAuthenticationService.h:27
cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const override
Definition: RelationalAuthenticationService.cc:46
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
SiStripCommissioningSource_FromEDM_cfg.inputPath
inputPath
Definition: SiStripCommissioningSource_FromEDM_cfg.py:8
DEFINE_CORALSERVICE
#define DEFINE_CORALSERVICE(type, name)
Definition: CoralServiceMacros.h:7
cond::auth::COND_AUTH_PATH_PROPERTY
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:43
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
Auth.h
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
crabWrapper.key
key
Definition: crabWrapper.py:19
cond::RelationalAuthenticationService::RelationalAuthenticationService::principalName
std::string principalName() override
Definition: RelationalAuthenticationService.cc:89
cond::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18