~jaypipes/drizzle/refactor-trx-log-applier

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Jay Pipes
  • Date: 2010-03-05 18:24:28 UTC
  • mfrom: (1273.1.51 staging)
  • Revision ID: jpipes@serialcoder-20100305182428-9m16fszbs3mvdhe0
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "config.h"
22
22
#include "drizzled/plugin/authentication.h"
23
 
#include "drizzled/errmsg_print.h"
 
23
#include "drizzled/error.h"
24
24
#include "drizzled/plugin/registry.h"
25
25
#include "drizzled/gettext.h"
 
26
#include "drizzled/security_context.h"
26
27
 
27
28
#include <vector>
28
29
 
51
52
 
52
53
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
53
54
{
54
 
  Session *session;
55
 
  const char *password;
 
55
  const SecurityContext &sctx;
 
56
  const string &password;
56
57
public:
57
 
  AuthenticateBy(Session *session_arg, const char *password_arg) :
 
58
  AuthenticateBy(const SecurityContext &sctx_arg, const string &password_arg) :
58
59
    unary_function<plugin::Authentication *, bool>(),
59
 
    session(session_arg), password(password_arg) {}
 
60
    sctx(sctx_arg), password(password_arg) {}
60
61
 
61
62
  inline result_type operator()(argument_type auth)
62
63
  {
63
 
    return auth->authenticate(session, password);
 
64
    return auth->authenticate(sctx, password);
64
65
  }
65
66
};
66
67
 
67
 
bool plugin::Authentication::isAuthenticated(Session *session,
68
 
                                             const char *password)
 
68
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
 
69
                                             const string &password)
69
70
{
70
71
  /* If we never loaded any auth plugins, just return true */
71
 
  if (all_authentication.size() == 0)
 
72
  if (all_authentication.empty())
72
73
    return true;
73
74
 
74
75
  /* Use find_if instead of foreach so that we can collect return codes */
75
76
  vector<plugin::Authentication *>::iterator iter=
76
77
    find_if(all_authentication.begin(), all_authentication.end(),
77
 
            AuthenticateBy(session, password));
 
78
            AuthenticateBy(sctx, password));
 
79
 
78
80
  /* If iter is == end() here, that means that all of the plugins returned
79
81
   * false, which in this case means they all succeeded. Since we want to 
80
82
   * return false on success, we return the value of the two being != 
81
83
   */
82
 
  return iter != all_authentication.end();
 
84
  if (iter != all_authentication.end())
 
85
  {
 
86
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
 
87
             sctx.getUser().c_str(),
 
88
             sctx.getIp().c_str(),
 
89
             password.empty() ? ER(ER_NO) : ER(ER_YES));
 
90
    return true;
 
91
  }
 
92
  return false;
83
93
}
84
94
 
85
95
} /* namespace drizzled */