21
21
#include "config.h"
22
22
#include "drizzled/plugin/authentication.h"
23
#include "drizzled/error.h"
23
#include "drizzled/errmsg_print.h"
24
24
#include "drizzled/plugin/registry.h"
25
25
#include "drizzled/gettext.h"
26
#include "drizzled/security_context.h"
53
52
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
55
const SecurityContext &sctx;
56
const string &password;
58
AuthenticateBy(const SecurityContext &sctx_arg, const string &password_arg) :
57
AuthenticateBy(Session *session_arg, const char *password_arg) :
59
58
unary_function<plugin::Authentication *, bool>(),
60
sctx(sctx_arg), password(password_arg) {}
59
session(session_arg), password(password_arg) {}
62
61
inline result_type operator()(argument_type auth)
64
return auth->authenticate(sctx, password);
63
return auth->authenticate(session, password);
68
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
69
const string &password)
67
bool plugin::Authentication::isAuthenticated(Session *session,
71
70
/* If we never loaded any auth plugins, just return true */
72
if (all_authentication.empty())
71
if (all_authentication.size() == 0)
75
74
/* Use find_if instead of foreach so that we can collect return codes */
76
75
vector<plugin::Authentication *>::iterator iter=
77
76
find_if(all_authentication.begin(), all_authentication.end(),
78
AuthenticateBy(sctx, password));
80
/* We only require one plugin to return success in order to authenticate.
81
* If iter is == end() here, that means that all of the plugins returned
82
* false, which means they all failed.
77
AuthenticateBy(session, password));
78
/* If iter is == end() here, that means that all of the plugins returned
79
* false, which in this case means they all succeeded. Since we want to
80
* return false on success, we return the value of the two being !=
84
if (iter == all_authentication.end())
86
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
87
sctx.getUser().c_str(),
89
password.empty() ? ER(ER_NO) : ER(ER_YES));
82
return iter != all_authentication.end();
95
85
} /* namespace drizzled */