21
21
#include <config.h>
22
#include <boost/foreach.hpp>
22
23
#include <drizzled/plugin/authentication.h>
23
24
#include <drizzled/error.h>
24
25
#include <drizzled/gettext.h>
25
26
#include <drizzled/identifier.h>
32
std::vector<plugin::Authentication *> all_authentication;
35
bool plugin::Authentication::addPlugin(plugin::Authentication *auth)
31
static std::vector<plugin::Authentication*> all_authentication;
33
bool plugin::Authentication::addPlugin(plugin::Authentication* auth)
38
36
all_authentication.push_back(auth);
43
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
46
all_authentication.erase(std::find(all_authentication.begin(),
47
all_authentication.end(),
51
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
53
const identifier::User &sctx;
54
const std::string &password;
57
AuthenticateBy(const identifier::User &sctx_arg, const std::string &password_arg) :
58
std::unary_function<plugin::Authentication *, bool>(),
59
sctx(sctx_arg), password(password_arg) {}
61
inline result_type operator()(argument_type auth)
63
return auth->authenticate(sctx, password);
67
bool plugin::Authentication::isAuthenticated(const drizzled::identifier::User& sctx,
68
const std::string &password)
70
/* Use find_if instead of foreach so that we can collect return codes */
71
std::vector<plugin::Authentication *>::iterator iter=
72
std::find_if(all_authentication.begin(), all_authentication.end(),
73
AuthenticateBy(sctx, password));
75
/* We only require one plugin to return success in order to authenticate.
76
* If iter is == end() here, that means that all of the plugins returned
77
* false, which means they all failed.
79
if (iter == all_authentication.end())
40
void plugin::Authentication::removePlugin(plugin::Authentication* auth)
42
all_authentication.erase(std::find(all_authentication.begin(), all_authentication.end(), auth));
45
bool plugin::Authentication::isAuthenticated(const drizzled::identifier::User& sctx, const std::string& password)
47
BOOST_FOREACH(plugin::Authentication* auth, all_authentication)
49
if (auth->authenticate(sctx, password))
89
56
} /* namespace drizzled */