~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Brian Aker
  • Date: 2010-02-19 23:42:02 UTC
  • mto: (1273.19.18 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1309.
  • Revision ID: brian@gir.tangent.org-20100219234202-boogaw8j3folts51
Basic engine with test.

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