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