Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsAuthenticator.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsAuthenticator.cpp
4  *
5  * Description: Handles connection of user
6  *
7  * Created: 02/15/12 12:37:55
8  *
9  * Author: Benoit Daccache, ben.daccache@gmail.com
10  *
11  */
12 
13 #include "WsAuthenticator.h"
14 
15 #include <Include/WsGlobalConfig.h>
17 #include <Logger/WsLogger.h>
18 #include <dlfcn.h>
19 #include <stdio.h>
20 #include <iostream>
21 using namespace std;
22 
24 {
25 }
26 
28 {
29  if (m_auth != 0)
30  delete m_auth;
31 }
32 
33 int WsAuthenticator::authentify(const string& uid, const string& pass, const std::string& ip)
34 {
35  if (loadModule() == ErrorCode::Failure)
36  return ErrorCode::Failure;
37  m_uid = uid;
38  m_pass = pass;
39  m_ip = ip;
40  if (m_auth->authentify(m_uid, m_pass, ip) == ErrorCode::Failure) {
41  LOG(ERROR) << "WsAuthenticator::authentify() : Could not authentify " << m_uid << " : " << ip;
42  return ErrorCode::Failure;
43  }
44  LOG(INFO) << "WsAuthenticator::authentify() : Authentication success for " << m_uid << " : " << ip;
45  return ErrorCode::Success;
46 }
47 
49 {
50  if (m_auth != 0)
51  return m_auth->getUid();
52  return "";
53 }
54 
56 {
57  if (m_auth != 0)
58  return m_auth->getFirstName();
59  return "";
60 }
61 
63 {
64  if (m_auth != 0)
65  return m_auth->getSurname();
66  return "";
67 }
68 
70 {
71  if (m_auth != 0)
72  return m_auth->getEmail();
73  return "";
74 }
75 
77 {
78  if (m_auth != 0)
79  return m_auth->getUserGroups();
80  return set<string>();
81 }
82 
84 {
85  if (loadModule() == ErrorCode::Failure)
86  return set<string>();
87  return m_auth->getAllGroups();
88 }
89 
91 {
92  LOG(DEBUG) << "WsAuthenticator :: Loading auth module";
93  /* Get the module name to load from the confifuration */
94  string libName = WsGlobalProperties::instance()->get("global", "auth_libname", "libWsModAuthd.so");
95  /* Open the library file (the module) */
96  void* hndl = dlopen(libName.c_str(), RTLD_LAZY);
97  if ( hndl == NULL ) {
98  LOG(ERROR) << "WsAuthenticator::loadModule() : load ERROR " << dlerror();
99  return ErrorCode::Failure;
100  }
101  LOG(DEBUG) << "WsAuthenticator :: Building module";
102  /* Call the buildmodule function of the loaded so file */
103  pf_wsAuthMod func = (pf_wsAuthMod) dlsym(hndl, "buildModule");
104  m_auth = func();
105  LOG(DEBUG) << "WsAuthenticator :: Done loading";
106 }
Global properties.
std::string getUid()
return the user uid WsAuthenticator::authentify must be called before
#define DEBUG
Definition: WsLogger.h:27
std::string getSurname()
return the user surname WsAuthenticator::authentify must be called before
~WsAuthenticator()
Destructor.
WsAbstractAuth *(* pf_wsAuthMod)()
const int Failure
std::string getEmail()
return the user email WsAuthenticator::authentify must be called before
#define LOG
Definition: WsLogger.h:22
WsAuthenticator()
Constructor.
#define INFO
Definition: WsLogger.h:32
int loadModule()
loads the module and casts it as WsAbstractAuth object
std::set< std::string > getUserGroups()
return the user groups WsAuthenticator::authentify must be called before
std::set< std::string > getAllGroups()
return all the possible groups WsAuthenticator::authentify must be called before
std::string get(const std::string &section, const std::string &id, const std::string &def)
static WsGlobalProperties * instance()
int authentify(const std::string &uid, const std::string &pass="", const std::string &ip="")
authentify the user.
const int Success
std::string getFirstName()
return the user name WsAuthenticator::authentify must be called before
#define ERROR
Definition: WsLogger.h:42