From 18b3a48e842d1e13b5a8505f8fd18069836d8fa5 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 26 Aug 2013 03:04:28 +0000 Subject: Fix handling of login session expiration and incorrect caching of login redirect responses. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1517413 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/server/mod-eval.hpp | 45 +++++++++++++++++++------------ 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'sca-cpp/trunk/modules/server/mod-eval.hpp') diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index 204459e127..5c46f1c224 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -1266,14 +1266,14 @@ int handler(request_rec* r) { /** * Call an authenticator component to check a user's password. */ -authn_status checkPassword(request_rec* r, const char* u, const char* p) { +authn_status checkAuthnz(request_rec* r, const char* u, const char* p) { const gc_scoped_pool sp(r->pool); // Prevent FakeBasicAuth spoofing const string user = u; - const string password = p; - debug(user, "modeval::checkPassword::user"); - if (substr(user, 0, 1) != "/" && find(user, "/") != length(user) && password == "password") { + debug(user, "modeval::checkAuthnz::user"); + const bool extauth = find(user, "/") != length(user); + if (extauth && substr(user, 0, 1) != "/") { mkfailure(string("Encountered FakeBasicAuth spoof: ") + user, HTTP_UNAUTHORIZED); return AUTH_DENIED; } @@ -1286,35 +1286,46 @@ authn_status checkPassword(request_rec* r, const char* u, const char* p) { } // Retrieve the user's password hash - const list uid = pathValues(user); + const list uid = extauth? cdr(pathValues(user)) : pathValues(user); const failable val = failableResult(((value)sc.vhostc.authenticator)(cons("get", mklist(uid)))); - if (!hasContent(val)) { + if (!hasContent(val) || isNull(content(val))) { mkfailure(string("SCA authentication check user failed, user not found: ") + user, rcode(val), user != "admin"); return AUTH_USER_NOT_FOUND; } - const value hval = content(val); - const list hcontent = isList(hval) && !isNull(hval) && isList(car(hval)) && !isNull(car(hval))? assoc(value("content"), cdr(car(hval))) : nilListValue; - const list hassoc = isNull(hcontent)? nilListValue : assoc(value("hash"), cdr(hcontent)); - if (isNull(hassoc)) { + debug(content(val), "modeval::checkAuthnz::val"); + + const value authn = cdr(car(content(val))); + const list acontent = assoc(value("content"), authn); + const list aauthn = isNull(acontent)? nilListValue : assoc(value("authn"), cdr(acontent)); + const list ahash = isNull(aauthn)? nilListValue : assoc(value("hash"), cdr(aauthn)); + if (isNull(ahash)) { mkfailure(string("SCA authentication check user failed, hash not found: ") + user, -1, user != "admin"); return AUTH_USER_NOT_FOUND; } - const string hash = cadr(hassoc); - if (length(hash) == 0) { + const string uhash = cadr(ahash); + if (length(uhash) == 0) { mkfailure(string("SCA authentication check user failed: ") + user); return AUTH_USER_NOT_FOUND; } - // Cache the hash in the auth cache provider, if available - if (authnCacheStore != NULL) - authnCacheStore(r, "component", u, NULL, c_str(hash)); + // Use a fixed hash of the string 'password' for externally authenticated users as they + // don't present an actual password + const string hash = extauth? "$apr1$OPUrN0Kr$/tc96p1r6LdmvB0mly6gg0" : uhash; - // Validate the presented password against the hash + // Validate the password against the hash const apr_status_t rv = apr_password_validate(p, c_str(hash)); if (rv != APR_SUCCESS) { mkfailure(string("SCA authentication user password check failed: ") + user); return AUTH_DENIED; } + + // Update the user field of the request with the authenticated user + const list auser = assoc(value("user"), cdr(aauthn)); + if (!isNull(auser)) { + debug(c_str(cadr(auser)), "modeval::checkAuthnz::auth_user"); + apr_table_set(r->subprocess_env, "AUTHZ_USER", apr_pstrdup(r->pool, c_str(cadr(auser)))); + } + return AUTH_GRANTED; } @@ -1569,7 +1580,7 @@ const command_rec commands[] = { const authn_provider AuthnProvider = { - &checkPassword, + &checkAuthnz, NULL }; -- cgit v1.2.3