You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2016/03/01 21:01:11 UTC
[38/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack
to e44a372
Use Stack to dispatch to correct auth_module
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/58ac4f60
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/58ac4f60
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/58ac4f60
Branch: refs/heads/split_out_httpd_stack
Commit: 58ac4f60d21ab094ebfd06810122a31f6dbd1475
Parents: 675e3c7
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Feb 26 13:49:17 2016 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Mar 1 08:35:09 2016 -0800
----------------------------------------------------------------------
src/couch_httpd_auth_plugin.erl | 24 +++++++++++++-----------
src/couch_httpd_handler.erl | 13 ++-----------
2 files changed, 15 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/58ac4f60/src/couch_httpd_auth_plugin.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_auth_plugin.erl b/src/couch_httpd_auth_plugin.erl
index a0a2596..8e979b9 100644
--- a/src/couch_httpd_auth_plugin.erl
+++ b/src/couch_httpd_auth_plugin.erl
@@ -12,8 +12,8 @@
-module(couch_httpd_auth_plugin).
--export([authenticate/2]).
--export([authorize/2]).
+-export([authenticate/1]).
+-export([authorize/1]).
-export([default_authentication_handler/1]).
-export([cookie_authentication_handler/1]).
@@ -23,17 +23,19 @@
-include_lib("couch/include/couch_db.hrl").
--define(SERVICE_ID, chttpd_auth).
+-define(SERVICE_ID, couch_httpd_auth).
%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------
-authenticate(HttpReq, Default) ->
+authenticate(HttpReq) ->
+ Default = fun(#httpd{stack = Stack} = Req) -> Stack:authenticate(Req) end,
maybe_handle(authenticate, [HttpReq], Default).
-authorize(HttpReq, Default) ->
+authorize(HttpReq) ->
+ Default = fun(#httpd{stack = Stack} = Req) -> Stack:authorize(Req) end,
maybe_handle(authorize, [HttpReq], Default).
@@ -41,11 +43,11 @@ authorize(HttpReq, Default) ->
%% Default callbacks
%% ------------------------------------------------------------------
-default_authentication_handler(Req) ->
- couch_httpd_auth:default_authentication_handler(Req, chttpd_auth_cache).
+default_authentication_handler(#httpd{auth_module = AuthModule} = Req) ->
+ couch_httpd_auth:default_authentication_handler(Req, AuthModule).
-cookie_authentication_handler(Req) ->
- couch_httpd_auth:cookie_authentication_handler(Req, chttpd_auth_cache).
+cookie_authentication_handler(#httpd{auth_module = AuthModule} = Req) ->
+ couch_httpd_auth:cookie_authentication_handler(Req, AuthModule).
party_mode_handler(Req) ->
case config:get("chttpd", "require_valid_user", "false") of
@@ -60,8 +62,8 @@ party_mode_handler(Req) ->
end
end.
-handle_session_req(Req) ->
- couch_httpd_auth:handle_session_req(Req, chttpd_auth_cache).
+handle_session_req(#httpd{auth_module = AuthModule} = Req) ->
+ couch_httpd_auth:handle_session_req(Req, AuthModule).
%% ------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/58ac4f60/src/couch_httpd_handler.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_handler.erl b/src/couch_httpd_handler.erl
index 0e95c8a..0149d54 100644
--- a/src/couch_httpd_handler.erl
+++ b/src/couch_httpd_handler.erl
@@ -215,11 +215,10 @@ process_request(#httpd{mochi_req = MochiReq, stack = Stack} = HttpReq) ->
check_request_uri_length(RawUri),
case couch_httpd_cors:maybe_handle_preflight_request(HttpReq) of
not_preflight ->
- case couch_httpd_auth_plugin:authenticate(HttpReq, fun authenticate_request/1) of
+ case couch_httpd_auth_plugin:authenticate(HttpReq) of
#httpd{} = Req ->
HandlerFun = couch_httpd_handlers:url_handler(HandlerKey, Stack),
- AuthorizedReq = couch_httpd_auth_plugin:authorize(possibly_hack(Req),
- fun chttpd_auth_request:authorize_request/1),
+ AuthorizedReq = couch_httpd_auth_plugin:authorize(possibly_hack(Req)),
{AuthorizedReq, HandlerFun(AuthorizedReq)};
Response ->
{HttpReq, Response}
@@ -396,14 +395,6 @@ extract_cookie(#httpd{mochi_req = MochiReq}) ->
end.
%%% end hack
-authenticate_request(Req) ->
- AuthenticationFuns = [
- {<<"cookie">>, fun couch_httpd_auth_plugin:cookie_authentication_handler/1},
- {<<"default">>, fun couch_httpd_auth_plugin:default_authentication_handler/1},
- {<<"local">>, fun couch_httpd_auth_plugin:party_mode_handler/1} %% should be last
- ],
- authenticate_request(Req, chttpd_auth_cache, AuthenticationFuns).
-
authenticate_request(#httpd{} = Req0, AuthModule, AuthFuns) ->
Req = Req0#httpd{
auth_module = AuthModule,