~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Brian Aker
  • Date: 2010-11-06 15:43:10 UTC
  • mfrom: (1908.1.1 merge)
  • Revision ID: brian@tangent.org-20101106154310-g1jpjzwbc53pfc4f
Filesort encapsulation, plus modification to copy contructor

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#include <vector>
28
28
 
 
29
using namespace std;
 
30
 
29
31
namespace drizzled
30
32
{
31
33
 
42
44
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
43
45
{
44
46
  if (auth != NULL)
45
 
    all_authentication.erase(std::find(all_authentication.begin(),
46
 
                                       all_authentication.end(),
47
 
                                       auth));
 
47
    all_authentication.erase(find(all_authentication.begin(),
 
48
                                  all_authentication.end(),
 
49
                                  auth));
48
50
}
49
51
 
50
 
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
 
52
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
51
53
{
52
54
  const SecurityContext &sctx;
53
 
  const std::string &password;
 
55
  const string &password;
54
56
public:
55
 
  AuthenticateBy(const SecurityContext &sctx_arg, const std::string &password_arg) :
56
 
    std::unary_function<plugin::Authentication *, bool>(),
 
57
  AuthenticateBy(const SecurityContext &sctx_arg, const string &password_arg) :
 
58
    unary_function<plugin::Authentication *, bool>(),
57
59
    sctx(sctx_arg), password(password_arg) {}
58
60
 
59
61
  inline result_type operator()(argument_type auth)
63
65
};
64
66
 
65
67
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
66
 
                                             const std::string &password)
 
68
                                             const string &password)
67
69
{
68
70
  /* If we never loaded any auth plugins, just return true */
69
71
  if (all_authentication.empty())
70
72
    return true;
71
73
 
72
74
  /* Use find_if instead of foreach so that we can collect return codes */
73
 
  std::vector<plugin::Authentication *>::iterator iter=
74
 
    std::find_if(all_authentication.begin(), all_authentication.end(),
75
 
                 AuthenticateBy(sctx, password));
 
75
  vector<plugin::Authentication *>::iterator iter=
 
76
    find_if(all_authentication.begin(), all_authentication.end(),
 
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