[GitHub] couchdb-chttpd pull request #147: Make auth handlers configurable.

2016-10-19 Thread dmunch
Github user dmunch closed the pull request at:

https://github.com/apache/couchdb-chttpd/pull/147


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] couchdb-chttpd pull request #147: Make auth handlers configurable.

2016-10-17 Thread rnewson
Github user rnewson commented on a diff in the pull request:

https://github.com/apache/couchdb-chttpd/pull/147#discussion_r83634499
  
--- Diff: src/chttpd.erl ---
@@ -464,12 +466,37 @@ extract_cookie(#httpd{mochi_req = MochiReq}) ->
 end.
 %%% end hack
 
-authenticate_request(Req) ->
-AuthenticationFuns = [
-{<<"cookie">>, fun chttpd_auth:cookie_authentication_handler/1},
-{<<"default">>, fun chttpd_auth:default_authentication_handler/1},
+set_auth_handlers() ->
+AuthenticationDefault =  "{chttpd_auth, cookie_authentication_handler},
+  {chttpd_auth, default_authentication_handler}",
+AuthenticationSrcs = couch_httpd:make_fun_spec_strs(
+config:get("chttpd", "authentication_handlers", 
AuthenticationDefault)),
+AuthHandlers = lists:map(
+fun(A) -> {auth_handler_name(A), couch_httpd:make_arity_1_fun(A)} 
end, AuthenticationSrcs),
+AuthenticationFuns = AuthHandlers ++ [
 fun chttpd_auth:party_mode_handler/1 %% must be last
 ],
+ok = application:set_env(chttpd, auth_handlers, AuthenticationFuns).
+
+% SpecStr is a string like "{my_module, my_fun}"
+% Takes the first token of the function name in front '_' as auth handler 
name
+% e.g. 
+% chttpd_auth:default_authentication_handler: default
+% chttpd_auth_cookie_authentication_handler: cookie
+% couch_http_auth:proxy_authentication_handler: proxy
+%
+% couch_http:auth_handler_name can't be used here, since it assumes the 
name 
+% of the auth handler to be the 6th token split by [\\W_]
+% - this only works for modules with exactly two underscores in their name
+% - is not very robust (a space after the ',' is assumed) 
+auth_handler_name(SpecStr) ->
+case couch_util:parse_term(SpecStr) of
--- End diff --

a case statement with only one clause seems odd.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] couchdb-chttpd pull request #147: Make auth handlers configurable.

2016-10-17 Thread dmunch
GitHub user dmunch opened a pull request:

https://github.com/apache/couchdb-chttpd/pull/147

Make auth handlers configurable.

Unit tests pass, dev cluster runs. Plus I'm able to use a modified version 
of couch_jwt_auth.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/dmunch/couchdb-chttpd 
feature-configurable-auth-handlers

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/couchdb-chttpd/pull/147.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #147


commit 46a2a634df57067426da8ed53e815ddb60f1d67b
Author: Daniel Münch 
Date:   2016-10-15T18:16:53Z

Make auth handlers configurable.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---