~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Patrick Crews
  • Date: 2010-12-07 20:02:50 UTC
  • Revision ID: gleebix@gmail.com-20101207200250-6a27jgqalgw5bsb5
Added disabled.def file to disable drizzleslap due to Bug#684269.  Need to skip for tarball release this round

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
22
22
#include "drizzled/plugin/authentication.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/gettext.h"
25
 
#include "drizzled/identifier.h"
 
25
#include "drizzled/security_context.h"
26
26
 
27
27
#include <vector>
28
28
 
36
36
{
37
37
  if (auth != NULL)
38
38
    all_authentication.push_back(auth);
39
 
 
40
39
  return false;
41
40
}
42
41
 
50
49
 
51
50
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
52
51
{
53
 
  const identifier::User &sctx;
 
52
  const SecurityContext &sctx;
54
53
  const std::string &password;
55
 
 
56
54
public:
57
 
  AuthenticateBy(const identifier::User &sctx_arg, const std::string &password_arg) :
 
55
  AuthenticateBy(const SecurityContext &sctx_arg, const std::string &password_arg) :
58
56
    std::unary_function<plugin::Authentication *, bool>(),
59
57
    sctx(sctx_arg), password(password_arg) {}
60
58
 
64
62
  }
65
63
};
66
64
 
67
 
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_shared_ptr sctx,
 
65
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
68
66
                                             const std::string &password)
69
67
{
70
68
  /* If we never loaded any auth plugins, just return true */
74
72
  /* Use find_if instead of foreach so that we can collect return codes */
75
73
  std::vector<plugin::Authentication *>::iterator iter=
76
74
    std::find_if(all_authentication.begin(), all_authentication.end(),
77
 
                 AuthenticateBy(*sctx, password));
 
75
                 AuthenticateBy(sctx, password));
78
76
 
79
77
  /* We only require one plugin to return success in order to authenticate.
80
78
   * If iter is == end() here, that means that all of the plugins returned
83
81
  if (iter == all_authentication.end())
84
82
  {
85
83
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
86
 
             sctx->username().c_str(),
87
 
             sctx->address().c_str(),
 
84
             sctx.getUser().c_str(),
 
85
             sctx.getIp().c_str(),
88
86
             password.empty() ? ER(ER_NO) : ER(ER_YES));
89
 
 
90
87
    return false;
91
88
  }
92
 
 
93
89
  return true;
94
90
}
95
91