Merge lp:~ansharyan015/drizzle/auth_http_dynamic into lp:drizzle

Proposed by Daniel Nichter
Status: Merged
Approved by: Brian Aker
Approved revision: 2565
Merged at revision: 2570
Proposed branch: lp:~ansharyan015/drizzle/auth_http_dynamic
Merge into: lp:drizzle
Diff against target: 149 lines (+52/-10)
2 files modified
plugin/auth_http/auth_http.cc (+48/-6)
plugin/auth_http/docs/index.rst (+4/-4)
To merge this branch: bzr merge lp:~ansharyan015/drizzle/auth_http_dynamic
Reviewer Review Type Date Requested Status
Daniel Nichter (community) code review Approve
Drizzle Merge Team Pending
Review via email: mp+114033@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugin/auth_http/auth_http.cc'
--- plugin/auth_http/auth_http.cc 2012-01-15 20:54:59 +0000
+++ plugin/auth_http/auth_http.cc 2012-07-09 19:53:20 +0000
@@ -24,6 +24,8 @@
24#include <string>24#include <string>
25#include <cassert>25#include <cassert>
26#include <boost/program_options.hpp>26#include <boost/program_options.hpp>
27
28#include <drizzled/item.h>
27#include <drizzled/module/option_map.h>29#include <drizzled/module/option_map.h>
28#include <drizzled/identifier.h>30#include <drizzled/identifier.h>
29#include <drizzled/plugin/authentication.h>31#include <drizzled/plugin/authentication.h>
@@ -32,6 +34,9 @@
32using namespace drizzled;34using namespace drizzled;
33using namespace std;35using namespace std;
3436
37namespace auth_http {
38bool updateAuthURL(Session *, set_var *);
39
35static size_t curl_cb_read(void *ptr, size_t size, size_t nmemb, void *stream)40static size_t curl_cb_read(void *ptr, size_t size, size_t nmemb, void *stream)
36{41{
37 (void) ptr;42 (void) ptr;
@@ -44,11 +49,11 @@
44{49{
45 CURLcode rv;50 CURLcode rv;
46 CURL *curl_handle;51 CURL *curl_handle;
47 const std::string auth_url;52 std::string sysvar_auth_url;
48public:53public:
49 Auth_http(std::string name_arg, const std::string &url_arg) :54 Auth_http(std::string name_arg, const std::string &url_arg) :
50 drizzled::plugin::Authentication(name_arg),55 drizzled::plugin::Authentication(name_arg),
51 auth_url(url_arg)56 sysvar_auth_url(url_arg)
52 {57 {
53 // we are trusting that plugin initializers are called singlethreaded at startup58 // we are trusting that plugin initializers are called singlethreaded at startup
54 // if something else also calls curl_global_init() in a threadrace while we are here,59 // if something else also calls curl_global_init() in a threadrace while we are here,
@@ -66,6 +71,22 @@
66 // set the read callback. this shouldnt get called, because we are doing a HEAD71 // set the read callback. this shouldnt get called, because we are doing a HEAD
67 rv= curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, curl_cb_read);72 rv= curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, curl_cb_read);
68 }73 }
74
75 std::string& getAuthURL()
76 {
77 return sysvar_auth_url;
78 }
79
80 bool setAuthURL(std::string& new_auth_url)
81 {
82 if (new_auth_url.empty())
83 {
84 errmsg_printf(error::ERROR, _("auth url cannot be an empty string"));
85 return false; // error
86 }
87 sysvar_auth_url= new_auth_url;
88 return true;
89 }
6990
70 ~Auth_http()91 ~Auth_http()
71 {92 {
@@ -80,7 +101,7 @@
80 assert(sctx.username().c_str());101 assert(sctx.username().c_str());
81102
82 // set the parameters: url, username, password103 // set the parameters: url, username, password
83 rv= curl_easy_setopt(curl_handle, CURLOPT_URL, auth_url.c_str());104 rv= curl_easy_setopt(curl_handle, CURLOPT_URL, sysvar_auth_url.c_str());
84#if defined(HAVE_CURLOPT_USERNAME)105#if defined(HAVE_CURLOPT_USERNAME)
85106
86 rv= curl_easy_setopt(curl_handle, CURLOPT_USERNAME,107 rv= curl_easy_setopt(curl_handle, CURLOPT_USERNAME,
@@ -116,6 +137,26 @@
116137
117Auth_http* auth= NULL;138Auth_http* auth= NULL;
118139
140/**
141 * This function is called when the value of auth_http_url is changed in the system.
142 *
143 * @return False on success, True on error.
144 */
145bool updateAuthURL(Session *, set_var* var)
146{
147 if (not var->value->str_value.empty())
148 {
149 std::string new_auth_url(var->value->str_value.data());
150 if (auth->setAuthURL(new_auth_url))
151 return false; //success
152 else
153 return true; // error
154 }
155 errmsg_printf(error::ERROR, _("auth_http url cannot be NULL"));
156 return true; // error
157}
158
159
119static int initialize(drizzled::module::Context &context)160static int initialize(drizzled::module::Context &context)
120{161{
121 const module::option_map &vm= context.getOptions();162 const module::option_map &vm= context.getOptions();
@@ -140,7 +181,7 @@
140181
141 auth= new Auth_http("auth_http", auth_url);182 auth= new Auth_http("auth_http", auth_url);
142 context.add(auth);183 context.add(auth);
143 context.registerVariable(new sys_var_const_string_val("url", auth_url));184 context.registerVariable(new sys_var_std_string("url", auth->getAuthURL(), NULL, &updateAuthURL));
144185
145 return 0;186 return 0;
146}187}
@@ -151,6 +192,7 @@
151 N_("URL for HTTP Auth check"));192 N_("URL for HTTP Auth check"));
152} 193}
153194
195} /* namespace auth_http */
154196
155DRIZZLE_DECLARE_PLUGIN197DRIZZLE_DECLARE_PLUGIN
156{198{
@@ -160,8 +202,8 @@
160 "Mark Atwood",202 "Mark Atwood",
161 N_("Authenication against a web server using HTTP"),203 N_("Authenication against a web server using HTTP"),
162 PLUGIN_LICENSE_GPL,204 PLUGIN_LICENSE_GPL,
163 initialize,205 auth_http::initialize,
164 NULL,206 NULL,
165 init_options207 auth_http::init_options
166}208}
167DRIZZLE_DECLARE_PLUGIN_END;209DRIZZLE_DECLARE_PLUGIN_END;
168210
=== modified file 'plugin/auth_http/docs/index.rst'
--- plugin/auth_http/docs/index.rst 2011-11-06 00:00:03 +0000
+++ plugin/auth_http/docs/index.rst 2012-07-09 19:53:20 +0000
@@ -3,9 +3,9 @@
3HTTP Authentication3HTTP Authentication
4===================4===================
55
6:program:`auth_http` is an authentication plugin that authenticates connections6:program:`auth_http` is an :doc:`/administration/authorization` plugin that authenticates connections using web-based HTTP authentication through a URL.
7using web-based HTTP authentication through a URL. A web server is required7When :program:`drizzled` is started with ``--plugin-add=auth_http``, the http based authorization plugin is loaded. To enable the plugin, it is required to provide the server url against which the authentication is being made using ``--auth-http.url=<server url>``. The authetication server url can be dynamically changed using ``SET GLOBAL auth_http_url="<new server url>"``.
8to provide authentication. For example, see Apache's documentation8A web server is required to provide authentication. For example, see Apache's documentation
9for `Authentication, Authorization and Access Control <http://httpd.apache.org/docs/2.0/howto/auth.html>`_.9for `Authentication, Authorization and Access Control <http://httpd.apache.org/docs/2.0/howto/auth.html>`_.
10Currently, SSL connections are not supported.10Currently, SSL connections are not supported.
1111
@@ -62,7 +62,7 @@
62* ``auth_http_url``62* ``auth_http_url``
6363
64 :Scope: Global64 :Scope: Global
65 :Dynamic: No65 :Dynamic: Yes
66 :Option: :option:`--auth-http.url`66 :Option: :option:`--auth-http.url`
6767
68 URL for HTTP authentication.68 URL for HTTP authentication.

Subscribers

People subscribed via source and target branches

to all changes: