~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Brian Aker
  • Date: 2010-12-18 10:14:05 UTC
  • mfrom: (2008.1.3 clean)
  • Revision ID: brian@tangent.org-20101218101405-qjbse29shi9coklg
Merge of user identifier work

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "drizzled/plugin/authentication.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/gettext.h"
25
 
#include "drizzled/security_context.h"
 
25
#include "drizzled/identifier.h"
26
26
 
27
27
#include <vector>
28
28
 
36
36
{
37
37
  if (auth != NULL)
38
38
    all_authentication.push_back(auth);
 
39
 
39
40
  return false;
40
41
}
41
42
 
49
50
 
50
51
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
51
52
{
52
 
  const SecurityContext &sctx;
 
53
  const identifier::User &sctx;
53
54
  const std::string &password;
 
55
 
54
56
public:
55
 
  AuthenticateBy(const SecurityContext &sctx_arg, const std::string &password_arg) :
 
57
  AuthenticateBy(const identifier::User &sctx_arg, const std::string &password_arg) :
56
58
    std::unary_function<plugin::Authentication *, bool>(),
57
59
    sctx(sctx_arg), password(password_arg) {}
58
60
 
62
64
  }
63
65
};
64
66
 
65
 
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
 
67
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_shared_ptr sctx,
66
68
                                             const std::string &password)
67
69
{
68
70
  /* If we never loaded any auth plugins, just return true */
72
74
  /* Use find_if instead of foreach so that we can collect return codes */
73
75
  std::vector<plugin::Authentication *>::iterator iter=
74
76
    std::find_if(all_authentication.begin(), all_authentication.end(),
75
 
                 AuthenticateBy(sctx, password));
 
77
                 AuthenticateBy(*sctx, password));
76
78
 
77
79
  /* We only require one plugin to return success in order to authenticate.
78
80
   * If iter is == end() here, that means that all of the plugins returned
81
83
  if (iter == all_authentication.end())
82
84
  {
83
85
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
84
 
             sctx.getUser().c_str(),
85
 
             sctx.getIp().c_str(),
 
86
             sctx->username().c_str(),
 
87
             sctx->address().c_str(),
86
88
             password.empty() ? ER(ER_NO) : ER(ER_YES));
 
89
 
87
90
    return false;
88
91
  }
 
92
 
89
93
  return true;
90
94
}
91
95