1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/plugin/authentication.h"
23
#include "drizzled/error.h"
24
#include "drizzled/gettext.h"
25
#include "drizzled/security_context.h"
34
std::vector<plugin::Authentication *> all_authentication;
37
bool plugin::Authentication::addPlugin(plugin::Authentication *auth)
40
all_authentication.push_back(auth);
44
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
47
all_authentication.erase(find(all_authentication.begin(),
48
all_authentication.end(),
52
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
54
const SecurityContext &sctx;
55
const string &password;
57
AuthenticateBy(const SecurityContext &sctx_arg, const string &password_arg) :
58
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 SecurityContext &sctx,
68
const string &password)
70
/* If we never loaded any auth plugins, just return true */
71
if (all_authentication.empty())
74
/* Use find_if instead of foreach so that we can collect return codes */
75
vector<plugin::Authentication *>::iterator iter=
76
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.
83
if (iter == all_authentication.end())
85
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
86
sctx.getUser().c_str(),
88
password.empty() ? ER(ER_NO) : ER(ER_YES));
94
} /* namespace drizzled */