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
1=== modified file 'plugin/auth_http/auth_http.cc'
2--- plugin/auth_http/auth_http.cc 2012-01-15 20:54:59 +0000
3+++ plugin/auth_http/auth_http.cc 2012-07-09 19:53:20 +0000
4@@ -24,6 +24,8 @@
5 #include <string>
6 #include <cassert>
7 #include <boost/program_options.hpp>
8+
9+#include <drizzled/item.h>
10 #include <drizzled/module/option_map.h>
11 #include <drizzled/identifier.h>
12 #include <drizzled/plugin/authentication.h>
13@@ -32,6 +34,9 @@
14 using namespace drizzled;
15 using namespace std;
16
17+namespace auth_http {
18+bool updateAuthURL(Session *, set_var *);
19+
20 static size_t curl_cb_read(void *ptr, size_t size, size_t nmemb, void *stream)
21 {
22 (void) ptr;
23@@ -44,11 +49,11 @@
24 {
25 CURLcode rv;
26 CURL *curl_handle;
27- const std::string auth_url;
28+ std::string sysvar_auth_url;
29 public:
30 Auth_http(std::string name_arg, const std::string &url_arg) :
31 drizzled::plugin::Authentication(name_arg),
32- auth_url(url_arg)
33+ sysvar_auth_url(url_arg)
34 {
35 // we are trusting that plugin initializers are called singlethreaded at startup
36 // if something else also calls curl_global_init() in a threadrace while we are here,
37@@ -66,6 +71,22 @@
38 // set the read callback. this shouldnt get called, because we are doing a HEAD
39 rv= curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, curl_cb_read);
40 }
41+
42+ std::string& getAuthURL()
43+ {
44+ return sysvar_auth_url;
45+ }
46+
47+ bool setAuthURL(std::string& new_auth_url)
48+ {
49+ if (new_auth_url.empty())
50+ {
51+ errmsg_printf(error::ERROR, _("auth url cannot be an empty string"));
52+ return false; // error
53+ }
54+ sysvar_auth_url= new_auth_url;
55+ return true;
56+ }
57
58 ~Auth_http()
59 {
60@@ -80,7 +101,7 @@
61 assert(sctx.username().c_str());
62
63 // set the parameters: url, username, password
64- rv= curl_easy_setopt(curl_handle, CURLOPT_URL, auth_url.c_str());
65+ rv= curl_easy_setopt(curl_handle, CURLOPT_URL, sysvar_auth_url.c_str());
66 #if defined(HAVE_CURLOPT_USERNAME)
67
68 rv= curl_easy_setopt(curl_handle, CURLOPT_USERNAME,
69@@ -116,6 +137,26 @@
70
71 Auth_http* auth= NULL;
72
73+/**
74+ * This function is called when the value of auth_http_url is changed in the system.
75+ *
76+ * @return False on success, True on error.
77+ */
78+bool updateAuthURL(Session *, set_var* var)
79+{
80+ if (not var->value->str_value.empty())
81+ {
82+ std::string new_auth_url(var->value->str_value.data());
83+ if (auth->setAuthURL(new_auth_url))
84+ return false; //success
85+ else
86+ return true; // error
87+ }
88+ errmsg_printf(error::ERROR, _("auth_http url cannot be NULL"));
89+ return true; // error
90+}
91+
92+
93 static int initialize(drizzled::module::Context &context)
94 {
95 const module::option_map &vm= context.getOptions();
96@@ -140,7 +181,7 @@
97
98 auth= new Auth_http("auth_http", auth_url);
99 context.add(auth);
100- context.registerVariable(new sys_var_const_string_val("url", auth_url));
101+ context.registerVariable(new sys_var_std_string("url", auth->getAuthURL(), NULL, &updateAuthURL));
102
103 return 0;
104 }
105@@ -151,6 +192,7 @@
106 N_("URL for HTTP Auth check"));
107 }
108
109+} /* namespace auth_http */
110
111 DRIZZLE_DECLARE_PLUGIN
112 {
113@@ -160,8 +202,8 @@
114 "Mark Atwood",
115 N_("Authenication against a web server using HTTP"),
116 PLUGIN_LICENSE_GPL,
117- initialize,
118+ auth_http::initialize,
119 NULL,
120- init_options
121+ auth_http::init_options
122 }
123 DRIZZLE_DECLARE_PLUGIN_END;
124
125=== modified file 'plugin/auth_http/docs/index.rst'
126--- plugin/auth_http/docs/index.rst 2011-11-06 00:00:03 +0000
127+++ plugin/auth_http/docs/index.rst 2012-07-09 19:53:20 +0000
128@@ -3,9 +3,9 @@
129 HTTP Authentication
130 ===================
131
132-:program:`auth_http` is an authentication plugin that authenticates connections
133-using web-based HTTP authentication through a URL. A web server is required
134-to provide authentication. For example, see Apache's documentation
135+:program:`auth_http` is an :doc:`/administration/authorization` plugin that authenticates connections using web-based HTTP authentication through a URL.
136+When :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>"``.
137+A web server is required to provide authentication. For example, see Apache's documentation
138 for `Authentication, Authorization and Access Control <http://httpd.apache.org/docs/2.0/howto/auth.html>`_.
139 Currently, SSL connections are not supported.
140
141@@ -62,7 +62,7 @@
142 * ``auth_http_url``
143
144 :Scope: Global
145- :Dynamic: No
146+ :Dynamic: Yes
147 :Option: :option:`--auth-http.url`
148
149 URL for HTTP authentication.

Subscribers

People subscribed via source and target branches

to all changes: