You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by tu...@apache.org on 2014/06/30 22:41:13 UTC
svn commit: r1606923 - in /hadoop/common/trunk/hadoop-common-project:
hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/
hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/
hadoop-common/ hadoop-common/s...
Author: tucu
Date: Mon Jun 30 20:41:13 2014
New Revision: 1606923
URL: http://svn.apache.org/r1606923
Log:
HADOOP-10710. hadoop.auth cookie is not properly constructed according to RFC2109. (Juan Yu via tucu)
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/AuthenticationFilter.java
hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpCookieFlag.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/AuthenticationFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/AuthenticationFilter.java?rev=1606923&r1=1606922&r2=1606923&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/AuthenticationFilter.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/AuthenticationFilter.java Mon Jun 30 20:41:13 2014
@@ -425,14 +425,20 @@ public class AuthenticationFilter implem
* cookie. It has no effect if its value < 0.
*
* XXX the following code duplicate some logic in Jetty / Servlet API,
- * because of the fact that Hadoop is stuck at servlet 3.0 and jetty 6
+ * because of the fact that Hadoop is stuck at servlet 2.5 and jetty 6
* right now.
*/
public static void createAuthCookie(HttpServletResponse resp, String token,
String domain, String path, long expires,
boolean isSecure) {
- StringBuilder sb = new StringBuilder(AuthenticatedURL.AUTH_COOKIE).append
- ("=").append(token);
+ StringBuilder sb = new StringBuilder(AuthenticatedURL.AUTH_COOKIE)
+ .append("=");
+ if (token != null && token.length() > 0) {
+ sb.append("\"")
+ .append(token)
+ .append("\"");
+ }
+ sb.append("; Version=1");
if (path != null) {
sb.append("; Path=").append(path);
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java?rev=1606923&r1=1606922&r2=1606923&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java Mon Jun 30 20:41:13 2014
@@ -531,21 +531,17 @@ public class TestAuthenticationFilter {
private static void parseCookieMap(String cookieHeader, HashMap<String,
String> cookieMap) {
- for (String pair : cookieHeader.split(";")) {
- String p = pair.trim();
- int idx = p.indexOf('=');
- final String k, v;
- if (idx == -1) {
- k = p;
- v = null;
- } else if (idx == p.length()) {
- k = p.substring(0, idx - 1);
- v = null;
- } else {
- k = p.substring(0, idx);
- v = p.substring(idx + 1);
+ List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
+ for (HttpCookie cookie : cookies) {
+ if (AuthenticatedURL.AUTH_COOKIE.equals(cookie.getName())) {
+ cookieMap.put(cookie.getName(), cookie.getValue());
+ if (cookie.getPath() != null) {
+ cookieMap.put("Path", cookie.getPath());
+ }
+ if (cookie.getDomain() != null) {
+ cookieMap.put("Domain", cookie.getDomain());
+ }
}
- cookieMap.put(k, v);
}
}
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1606923&r1=1606922&r2=1606923&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Mon Jun 30 20:41:13 2014
@@ -665,6 +665,9 @@ Release 2.5.0 - UNRELEASED
HADOOP-10715. Remove public GraphiteSink#setWriter (Babak Behzad via raviprak)
+ HADOOP-10710. hadoop.auth cookie is not properly constructed according to
+ RFC2109. (Juan Yu via tucu)
+
Release 2.4.1 - 2014-06-23
INCOMPATIBLE CHANGES
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpCookieFlag.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpCookieFlag.java?rev=1606923&r1=1606922&r2=1606923&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpCookieFlag.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpCookieFlag.java Mon Jun 30 20:41:13 2014
@@ -36,6 +36,8 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.security.GeneralSecurityException;
+import java.net.HttpCookie;
+import java.util.List;
public class TestHttpCookieFlag {
private static final String BASEDIR = System.getProperty("test.build.dir",
@@ -116,8 +118,12 @@ public class TestHttpCookieFlag {
.getConnectorAddress(0)));
HttpURLConnection conn = (HttpURLConnection) new URL(base,
"/echo").openConnection();
- Assert.assertEquals(AuthenticatedURL.AUTH_COOKIE + "=token; " +
- "HttpOnly", conn.getHeaderField("Set-Cookie"));
+
+ String header = conn.getHeaderField("Set-Cookie");
+ List<HttpCookie> cookies = HttpCookie.parse(header);
+ Assert.assertTrue(!cookies.isEmpty());
+ Assert.assertTrue(header.contains("; HttpOnly"));
+ Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
@Test
@@ -127,8 +133,13 @@ public class TestHttpCookieFlag {
HttpsURLConnection conn = (HttpsURLConnection) new URL(base,
"/echo").openConnection();
conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());
- Assert.assertEquals(AuthenticatedURL.AUTH_COOKIE + "=token; " +
- "Secure; HttpOnly", conn.getHeaderField("Set-Cookie"));
+
+ String header = conn.getHeaderField("Set-Cookie");
+ List<HttpCookie> cookies = HttpCookie.parse(header);
+ Assert.assertTrue(!cookies.isEmpty());
+ Assert.assertTrue(header.contains("; HttpOnly"));
+ Assert.assertTrue(cookies.get(0).getSecure());
+ Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
@AfterClass