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("No Authentication available for connection=\"");
64  msg += connectionString + "\".";
65  throw coral::AuthenticationServiceException( msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials", "");
66  }
67  return *creds;
68 }
69 
70 const coral::IAuthenticationCredentials&
72  const std::string& role ) const
73 {
74  const coral::IAuthenticationCredentials* creds = m_cache.get( connectionString, role );
75  if( !creds ){
76  std::string credsStoreConn = m_db.setUpForConnectionString( connectionString, m_authenticationPath );
77  coral::MessageStream log("cond::RelationalAuthenticationService::credentials");
78  log << coral::Debug << "Connecting to the credential repository in \"" << credsStoreConn << "\" with principal \""<<m_db.keyPrincipalName()<<"\"."<<coral::MessageStream::endmsg;
79  m_db.selectForUser( m_cache );
80  }
81  creds = m_cache.get( connectionString, role );
82  if( ! creds ){
83  std::string msg("No Authentication available for connection=\"");
84  msg += connectionString + "\".";
85  msg += " and role=\"" + role + "\".";
86  throw coral::AuthenticationServiceException( msg, "cond::RelationalAuthenticationService::RelationalAuthenticationService::credentials","");
87  }
88  return *creds;
89 }
90 
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.
list key
Definition: combine.py:13
const coral::IAuthenticationCredentials & credentials(const std::string &connectionString) const
const bool Debug