CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  : coral::Service( key ),
26  m_authenticationPath(""),
27  m_db(),
28  m_cache(),
29  m_callbackID(0)
30 {
31  boost::function1<void, std::string> cb(boost::bind(&cond::RelationalAuthenticationService::RelationalAuthenticationService::setAuthenticationPath, this, _1));
32 
33  coral::Property* pm = dynamic_cast<coral::Property*>(coral::Context::instance().PropertyManager().property(Auth::COND_AUTH_PATH_PROPERTY));
34  if(pm){
35  setAuthenticationPath( pm->get() );
36  m_callbackID = pm->registerCallback(cb);
37  }
38 }
39 
41 {
42 }
43 
44 void
46 {
47  m_authenticationPath = inputPath;
48  m_cache.reset();
49 }
50 
51 const coral::IAuthenticationCredentials&
53 {
54  const coral::IAuthenticationCredentials* creds = m_cache.get( connectionString );
55  if( !creds ){
56  std::string credsStoreConn = m_db.setUpForConnectionString( connectionString, m_authenticationPath );
57  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
58  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""<<m_db.keyPrincipalName()<<"\"."<<coral::MessageStream::endmsg;
59  m_db.selectForUser( m_cache );
60  }
61  creds = m_cache.get( connectionString );
62  if( ! creds ){
63  std::string msg("Connection to \"");
64  msg += connectionString + "\"";
65  msg += " with role \"COND_DEFAULT_ROLE\" is not available for ";
66  msg +=m_db.keyPrincipalName();
67  cond::throwException( msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials" );
68  }
69  return *creds;
70 }
71 
72 const coral::IAuthenticationCredentials&
74  const std::string& role ) const
75 {
76  const coral::IAuthenticationCredentials* creds = m_cache.get( connectionString, role );
77  if( !creds ){
78  std::string credsStoreConn = m_db.setUpForConnectionString( connectionString, m_authenticationPath );
79  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
80  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""<<m_db.keyPrincipalName()<<"\"."<<coral::MessageStream::endmsg;
81  m_db.selectForUser( m_cache );
82  }
83  creds = m_cache.get( connectionString, role );
84  if( ! creds ){
85  std::string msg("Connection to \"");
86  msg += connectionString + "\"";
87  msg += " with role \"" + role + "\" is not available for ";
88  msg +=m_db.keyPrincipalName();
89  cond::throwException( msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials" );
90  }
91  return *creds;
92 }
93 
static PFTauRenderPlugin instance
static const std::string COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
#define DEFINE_CORALSERVICE(type, name)
void setAuthenticationPath(const std::string &inputPath)
Sets the input file name.
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const
const bool Debug