Drizzled Public API Documentation

auth_all.cc

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 Brian Aker
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <fstream>
00024 #include <map>
00025 #include <string>
00026 #include <iostream>
00027 
00028 #include <boost/program_options.hpp>
00029 
00030 #include <drizzled/configmake.h>
00031 #include <drizzled/plugin/authentication.h>
00032 #include <drizzled/identifier.h>
00033 #include <drizzled/util/convert.h>
00034 #include <drizzled/module/option_map.h>
00035 
00036 namespace po= boost::program_options;
00037 namespace fs= boost::filesystem;
00038 
00039 using namespace std;
00040 using namespace drizzled;
00041 
00042 namespace auth_all
00043 {
00044 
00045 static bool opt_allow_anonymous;
00046 
00047 class AuthAll: public plugin::Authentication
00048 {
00049 public:
00050 
00051   AuthAll() :
00052     plugin::Authentication("auth_all")
00053   {
00054   }
00055 
00056 private:
00057 
00061   bool authenticate(const identifier::User &sctx, const string &)
00062   {
00063     if (not opt_allow_anonymous)
00064     {
00065       if (sctx.username().empty())
00066         return false;
00067     }
00068 
00069     return true;
00070   }
00071 };
00072 
00073 static int init(module::Context &context)
00074 {
00075   context.add(new AuthAll());
00076 
00077   return 0;
00078 }
00079 
00080 static void init_options(drizzled::module::option_context &context)
00081 {
00082   context("allow_anonymous", 
00083           po::value<bool>(&opt_allow_anonymous)->default_value(false),
00084           N_("Allow anonymous access"));
00085 }
00086 
00087 
00088 } /* namespace auth_all */
00089 
00090 DRIZZLE_DECLARE_PLUGIN
00091 {
00092   DRIZZLE_VERSION_ID,
00093   "Allow-All-Authentication",
00094   "1.0",
00095   "Brian Aker",
00096   "Data Dictionary for utility tables",
00097   PLUGIN_LICENSE_GPL,
00098   auth_all::init,
00099   NULL,
00100   auth_all::init_options
00101 }
00102 DRIZZLE_DECLARE_PLUGIN_END;