cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6451] Updating NewCookie parser to check HttpOnly and Expires
Date Thu, 11 Jun 2015 12:00:54 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ca829e305 -> eac58fa8e


[CXF-6451] Updating NewCookie parser to check HttpOnly and Expires


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/eac58fa8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/eac58fa8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/eac58fa8

Branch: refs/heads/master
Commit: eac58fa8ec4de374240e56847f39d540c9c39b22
Parents: ca829e3
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Jun 11 13:00:38 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Jun 11 13:00:38 2015 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/NewCookieHeaderProvider.java | 25 ++++++++++++++------
 .../jaxrs/impl/NewCookieHeaderProviderTest.java | 23 ++++++++++++++++++
 2 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/eac58fa8/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
index a050b86..7cb700f 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
@@ -19,10 +19,13 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import java.util.Date;
+
 import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 
 public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie> {
 
@@ -33,6 +36,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
     private static final String COMMENT = "Comment";
     private static final String SECURE = "Secure";
     private static final String EXPIRES = "Expires";
+    private static final String HTTP_ONLY = "HttpOnly";
         
     public NewCookie fromString(String c) {
         
@@ -45,8 +49,11 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
         String path = null;
         String domain = null;
         String comment = null;
-        int maxAge = -1;
+        int maxAge = NewCookie.DEFAULT_MAX_AGE;
         boolean isSecure = false;
+        Date expires = null;
+        boolean httpOnly = false;
+        int version = NewCookie.DEFAULT_VERSION;
         
         String[] tokens = StringUtils.split(c, ";");
         for (String token : tokens) {
@@ -54,7 +61,8 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
             
             int sepIndex = theToken.indexOf('=');
             String paramName = sepIndex != -1 ? theToken.substring(0, sepIndex) : theToken;
-            String paramValue = sepIndex == theToken.length() + 1 ? null : theToken.substring(sepIndex
+ 1);
+            String paramValue = sepIndex == -1 || sepIndex == theToken.length() - 1 
+                ? null : theToken.substring(sepIndex + 1);
             
             if (paramName.equalsIgnoreCase(MAX_AGE)) {
                 maxAge = Integer.parseInt(paramValue);
@@ -66,10 +74,13 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
                 comment = paramValue;
             } else if (paramName.equalsIgnoreCase(SECURE)) {
                 isSecure = true;
-            } else if (paramName.equalsIgnoreCase(EXPIRES) || paramName.equalsIgnoreCase(VERSION))
{
-                // ignore
-                continue;
-            } else {
+            } else if (paramName.equalsIgnoreCase(EXPIRES)) {
+                expires = HttpUtils.getHttpDate(paramValue);
+            } else if (paramName.equalsIgnoreCase(HTTP_ONLY)) {
+                httpOnly = true;
+            } else if (paramName.equalsIgnoreCase(VERSION)) {
+                version = Integer.parseInt(paramValue);
+            } else if (paramValue != null) {
                 name = paramName;
                 value = paramValue;
             }
@@ -79,7 +90,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
             throw new IllegalArgumentException("Set-Cookie is malformed : " + c);
         }
         
-        return new NewCookie(name, value, path, domain, comment, maxAge, isSecure);
+        return new NewCookie(name, value, path, domain, version, comment, maxAge, expires,
isSecure, httpOnly);
     }
 
     public String toString(NewCookie value) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/eac58fa8/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
index 6e62952..5f54f24 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
@@ -19,8 +19,12 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import java.util.Date;
+
 import javax.ws.rs.core.NewCookie;
 
+import org.apache.cxf.jaxrs.utils.HttpUtils;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -60,6 +64,25 @@ public class NewCookieHeaderProviderTest extends Assert {
     }
     
     @Test
+    public void testFromComplexStringWithExpiresAndHttpOnly() {
+        NewCookie c = NewCookie.valueOf(
+                      "foo=bar;Comment=comment;Path=path;Max-Age=10;Domain=domain;Secure;"
+                      + "Expires=Wed, 09 Jun 2021 10:18:14 GMT;HttpOnly;Version=1");
+        assertTrue("bar".equals(c.getValue())
+                   && "foo".equals(c.getName()));
+        assertTrue(1 == c.getVersion()
+                   && "path".equals(c.getPath())
+                   && "domain".equals(c.getDomain())
+                   && "comment".equals(c.getComment())
+                   && c.isSecure()
+                   && c.isHttpOnly()
+                   && 10 == c.getMaxAge());
+        Date d = c.getExpiry();
+        assertNotNull(d);
+        assertEquals("Wed, 09 Jun 2021 10:18:14 GMT", HttpUtils.toHttpDate(d));
+    }
+    
+    @Test
     public void testFromComplexStringLowerCase() {
         NewCookie c = NewCookie.valueOf(
                       "foo=bar;comment=comment;path=path;max-age=10;domain=domain;secure;version=1");


Mime
View raw message