18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/server_includes.h"
22
22
#include "drizzled/plugin/authentication.h"
23
#include "drizzled/error.h"
23
#include "drizzled/errmsg_print.h"
24
#include "drizzled/plugin/registry.h"
24
25
#include "drizzled/gettext.h"
25
#include "drizzled/identifier.h"
38
40
all_authentication.push_back(auth);
43
44
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
46
all_authentication.erase(std::find(all_authentication.begin(),
47
all_authentication.end(),
47
all_authentication.erase(find(all_authentication.begin(),
48
all_authentication.end(),
51
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
52
class AuthenticateBy : public 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) {}
57
AuthenticateBy(Session *session_arg, const char *password_arg) :
58
unary_function<plugin::Authentication *, bool>(),
59
session(session_arg), password(password_arg) {}
61
61
inline result_type operator()(argument_type auth)
63
return auth->authenticate(sctx, password);
63
return auth->authenticate(session, password);
67
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_shared_ptr sctx,
68
const std::string &password)
67
bool plugin::Authentication::isAuthenticated(Session *session,
70
70
/* If we never loaded any auth plugins, just return true */
71
if (all_authentication.empty())
71
if (all_authentication.size() == 0)
74
74
/* Use find_if instead of foreach so that we can collect return codes */
75
std::vector<plugin::Authentication *>::iterator iter=
76
std::find_if(all_authentication.begin(), all_authentication.end(),
77
AuthenticateBy(*sctx, password));
79
/* We only require one plugin to return success in order to authenticate.
80
* If iter is == end() here, that means that all of the plugins returned
81
* false, which means they all failed.
75
vector<plugin::Authentication *>::iterator iter=
76
find_if(all_authentication.begin(), all_authentication.end(),
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 !=
83
if (iter == all_authentication.end())
85
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
86
sctx->username().c_str(),
87
sctx->address().c_str(),
88
password.empty() ? ER(ER_NO) : ER(ER_YES));
82
return iter != all_authentication.end();
96
85
} /* namespace drizzled */