Drizzled Public API Documentation

auth_all.cc
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2011 Brian Aker
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 
23 #include <fstream>
24 #include <map>
25 #include <string>
26 #include <iostream>
27 
28 #include <boost/program_options.hpp>
29 
30 #include <drizzled/configmake.h>
31 #include <drizzled/plugin/authentication.h>
32 #include <drizzled/identifier.h>
33 #include <drizzled/util/convert.h>
35 
36 namespace po= boost::program_options;
37 namespace fs= boost::filesystem;
38 
39 using namespace std;
40 using namespace drizzled;
41 
42 namespace auth_all
43 {
44 
45 static bool opt_allow_anonymous;
46 
47 class AuthAll: public plugin::Authentication
48 {
49 public:
50 
51  AuthAll() :
52  plugin::Authentication("auth_all")
53  {
54  }
55 
56 private:
57 
61  bool authenticate(const identifier::User &sctx, const string &)
62  {
63  if (not opt_allow_anonymous)
64  {
65  if (sctx.username().empty())
66  return false;
67  }
68 
69  return true;
70  }
71 };
72 
73 static int init(module::Context &context)
74 {
75  context.add(new AuthAll());
76 
77  return 0;
78 }
79 
80 static void init_options(drizzled::module::option_context &context)
81 {
82  context("allow-anonymous",
83  po::value<bool>(&opt_allow_anonymous)->default_value(false),
84  N_("Allow anonymous access"));
85 }
86 
87 
88 } /* namespace auth_all */
89 
90 DRIZZLE_DECLARE_PLUGIN
91 {
92  DRIZZLE_VERSION_ID,
93  "auth_all",
94  "1.0",
95  "Brian Aker",
96  N_("Allows all users to authenticate regardless of username or password"),
97  PLUGIN_LICENSE_GPL,
98  auth_all::init,
99  NULL,
100  auth_all::init_options
101 }
102 DRIZZLE_DECLARE_PLUGIN_END;
A set of Session members describing the current authenticated user.
Definition: user.h:34
TODO: Rename this file - func.h is stupid.
An Proxy Wrapper around boost::program_options::variables_map.
bool authenticate(const identifier::User &sctx, const string &)
Definition: auth_all.cc:61