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) {
42  m_authenticationPath = 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;
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  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;
77  m_db.selectForUser(m_cache);
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");
cond::RelationalAuthenticationService::RelationalAuthenticationService::setAuthenticationPath
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
Definition: RelationalAuthenticationService.cc:40
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:61
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:24
CoralServiceMacros.h
Service
cond::RelationalAuthenticationService::RelationalAuthenticationService::~RelationalAuthenticationService
~RelationalAuthenticationService() override
Standard Destructor.
Definition: RelationalAuthenticationService.cc:38
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::RelationalAuthenticationService::RelationalAuthenticationService
Definition: RelationalAuthenticationService.h:26
cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const override
Definition: RelationalAuthenticationService.cc:47
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:27
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::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18