~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
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>
26
 
 
27
27
#include <vector>
28
28
 
29
 
namespace drizzled
30
 
{
31
 
 
32
 
std::vector<plugin::Authentication *> all_authentication;
33
 
 
34
 
 
35
 
bool plugin::Authentication::addPlugin(plugin::Authentication *auth)
36
 
{
37
 
  if (auth != NULL)
 
29
namespace drizzled {
 
30
 
 
31
static std::vector<plugin::Authentication*> all_authentication;
 
32
 
 
33
bool plugin::Authentication::addPlugin(plugin::Authentication* auth)
 
34
{
 
35
  if (auth)
38
36
    all_authentication.push_back(auth);
39
 
 
40
 
  return false;
41
 
}
42
 
 
43
 
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
44
 
{
45
 
  if (auth != NULL)
46
 
    all_authentication.erase(std::find(all_authentication.begin(),
47
 
                                       all_authentication.end(),
48
 
                                       auth));
49
 
}
50
 
 
51
 
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
52
 
{
53
 
  const identifier::User &sctx;
54
 
  const std::string &password;
55
 
 
56
 
public:
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) {}
60
 
 
61
 
  inline result_type operator()(argument_type auth)
62
 
  {
63
 
    return auth->authenticate(sctx, password);
64
 
  }
65
 
};
66
 
 
67
 
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_reference sctx,
68
 
                                             const std::string &password)
69
 
{
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));
74
 
 
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.
78
 
   */
79
 
  if (iter == all_authentication.end())
80
 
  {
81
 
    error::access(sctx);
82
 
 
83
 
    return false;
84
 
  }
85
 
 
86
 
  return true;
 
37
  return false;
 
38
}
 
39
 
 
40
void plugin::Authentication::removePlugin(plugin::Authentication* auth)
 
41
{
 
42
  all_authentication.erase(std::find(all_authentication.begin(), all_authentication.end(), auth));
 
43
}
 
44
 
 
45
bool plugin::Authentication::isAuthenticated(const drizzled::identifier::User& sctx, const std::string& password)
 
46
{
 
47
  BOOST_FOREACH(plugin::Authentication* auth, all_authentication)
 
48
  {
 
49
    if (auth->authenticate(sctx, password))
 
50
      return true;
 
51
  }
 
52
  error::access(sctx);
 
53
  return false;
87
54
}
88
55
 
89
56
} /* namespace drizzled */