From fb2406a635263875103a06763614eebcf77d297a Mon Sep 17 00:00:00 2001 From: Alejandro Abdelnur Date: Mon, 6 Jan 2014 18:11:38 +0000 Subject: [PATCH] HADOOP-10193. hadoop-auth's PseudoAuthenticationHandler can consume getInputStream. (gchanan via tucu) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1555955 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-auth/pom.xml | 5 +++++ .../server/PseudoAuthenticationHandler.java | 20 ++++++++++++++++++- .../TestPseudoAuthenticationHandler.java | 2 +- .../hadoop-common/CHANGES.txt | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-auth/pom.xml b/hadoop-common-project/hadoop-auth/pom.xml index dc841e5d52..1d913a637c 100644 --- a/hadoop-common-project/hadoop-auth/pom.xml +++ b/hadoop-common-project/hadoop-auth/pom.xml @@ -92,6 +92,11 @@ hadoop-minikdc test + + org.apache.httpcomponents + httpclient + compile + diff --git a/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/PseudoAuthenticationHandler.java b/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/PseudoAuthenticationHandler.java index 1a2f98c1c9..235081b961 100644 --- a/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/PseudoAuthenticationHandler.java +++ b/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/PseudoAuthenticationHandler.java @@ -16,10 +16,15 @@ import org.apache.hadoop.security.authentication.client.AuthenticationException; import org.apache.hadoop.security.authentication.client.PseudoAuthenticator; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.NameValuePair; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; import java.util.Properties; /** @@ -48,6 +53,7 @@ public class PseudoAuthenticationHandler implements AuthenticationHandler { */ public static final String ANONYMOUS_ALLOWED = TYPE + ".anonymous.allowed"; + private static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); private boolean acceptAnonymous; /** @@ -114,6 +120,18 @@ public boolean managementOperation(AuthenticationToken token, return true; } + private String getUserName(HttpServletRequest request) { + List list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET); + if (list != null) { + for (NameValuePair nv : list) { + if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) { + return nv.getValue(); + } + } + } + return null; + } + /** * Authenticates an HTTP client request. *

@@ -139,7 +157,7 @@ public boolean managementOperation(AuthenticationToken token, public AuthenticationToken authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException, AuthenticationException { AuthenticationToken token; - String userName = request.getParameter(PseudoAuthenticator.USER_NAME); + String userName = getUserName(request); if (userName == null) { if (getAcceptAnonymous()) { token = AuthenticationToken.ANONYMOUS; diff --git a/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestPseudoAuthenticationHandler.java b/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestPseudoAuthenticationHandler.java index da7eda7bc8..91c11031d9 100644 --- a/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestPseudoAuthenticationHandler.java +++ b/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestPseudoAuthenticationHandler.java @@ -94,7 +94,7 @@ private void _testUserName(boolean anonymous) throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); HttpServletResponse response = Mockito.mock(HttpServletResponse.class); - Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user"); + Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user"); AuthenticationToken token = handler.authenticate(request, response); diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index cdf3b7a1e5..cdff25522e 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -580,6 +580,9 @@ Release 2.3.0 - UNRELEASED HADOOP-10090. Jobtracker metrics not updated properly after execution of a mapreduce job. (ivanmi) + HADOOP-10193. hadoop-auth's PseudoAuthenticationHandler can consume getInputStream. + (gchanan via tucu) + Release 2.2.0 - 2013-10-13 INCOMPATIBLE CHANGES