chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1357300 - in /chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies: CmisCookieManager.java CmisCookieStoreImpl.java CmisHttpCookie.java
Date Wed, 04 Jul 2012 15:15:49 GMT
Author: fmui
Date: Wed Jul  4 15:15:49 2012
New Revision: 1357300

URL: http://svn.apache.org/viewvc?rev=1357300&view=rev
Log:
Client: support for RFC 6265 cookies

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieManager.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieStoreImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisHttpCookie.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieManager.java?rev=1357300&r1=1357299&r2=1357300&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieManager.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieManager.java
Wed Jul  4 15:15:49 2012
@@ -40,7 +40,8 @@ import org.slf4j.LoggerFactory;
 /**
  * Cookie Manager.
  * 
- * This implementation conforms to RFC 2965, section 3.3.
+ * This implementation conforms to RFC 2965, section 3.3 with some RFC 6265
+ * extensions.
  */
 public class CmisCookieManager implements Serializable {
     private static final long serialVersionUID = 1L;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieStoreImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieStoreImpl.java?rev=1357300&r1=1357299&r2=1357300&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieStoreImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisCookieStoreImpl.java
Wed Jul  4 15:15:49 2012
@@ -31,13 +31,17 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 /**
  * Provides an in-memory cookie store.
  */
-class CmisCookieStoreImpl implements Serializable {
+public class CmisCookieStoreImpl implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    private static final String IP_ADDRESS_PATTERN_STR = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
+    private static final Pattern IP_ADDRESS_PATTERN = Pattern.compile(IP_ADDRESS_PATTERN_STR);
+
     private final Map<URI, ArrayList<CmisHttpCookie>> storeMap;
 
     public CmisCookieStoreImpl() {
@@ -102,20 +106,42 @@ class CmisCookieStoreImpl implements Ser
                     secure = scheme.toLowerCase().startsWith("https");
                 }
 
+                String newHost = uri.getHost().toLowerCase();
+
                 List<CmisHttpCookie> listCookie = storeMap.get(u);
                 Iterator<CmisHttpCookie> iter = listCookie.iterator();
                 while (iter.hasNext()) {
                     CmisHttpCookie cookie = iter.next();
-                    if (CmisHttpCookie.domainMatches(cookie.getDomain(), uri.getHost()))
{
-                        if (cookie.hasExpired()) {
-                            iter.remove();
-                            if (listCookie.isEmpty()) {
-                                storeMap.remove(u);
-                            }
-                        } else if (!(cookie.hasExpired() || cookies.contains(cookie))) {
-                            if (!cookie.getSecure() || secure) {
+
+                    if (cookie.hasExpired()) {
+                        iter.remove();
+                        if (listCookie.isEmpty()) {
+                            storeMap.remove(u);
+                        }
+                    } else if (!cookies.contains(cookie) && (!cookie.getSecure()
|| secure)
+                            && cookie.getDomain() != null) {
+                        String newDomain = cookie.getDomain().toLowerCase();
+
+                        if (isIPAddress(newHost)) {
+                            if (newHost.equals(newDomain)) {
                                 cookies.add(cookie);
                             }
+                        } else {
+                            if (cookie.getVersion() == 0) {
+                                // Netscape, RFC 2109, RFC 6265
+                                if (newHost.endsWith(newDomain)) {
+                                    if (newHost.length() == newDomain.length()) {
+                                        cookies.add(cookie);
+                                    } else if (newDomain.startsWith(".")) {
+                                        cookies.add(cookie);
+                                    }
+                                }
+                            } else if (cookie.getVersion() == 1) {
+                                // RFC 2965
+                                if (CmisHttpCookie.domainMatches(cookie.getDomain(), newHost))
{
+                                    cookies.add(cookie);
+                                }
+                            }
                         }
                     }
                 }
@@ -125,6 +151,20 @@ class CmisCookieStoreImpl implements Ser
         return cookies;
     }
 
+    private boolean isIPAddress(String s) {
+        if (s.startsWith("[")) {
+            // IPv6
+            return true;
+        }
+
+        if (IP_ADDRESS_PATTERN.matcher(s).matches()) {
+            // IPv4
+            return true;
+        }
+
+        return false;
+    }
+
     private void cleanCookieList(List<CmisHttpCookie> cookies) {
         Iterator<CmisHttpCookie> iter = cookies.iterator();
         while (iter.hasNext()) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisHttpCookie.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisHttpCookie.java?rev=1357300&r1=1357299&r2=1357300&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisHttpCookie.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/cookies/CmisHttpCookie.java
Wed Jul  4 15:15:49 2012
@@ -34,8 +34,9 @@ import java.util.regex.Pattern;
 /**
  * This class represents a http cookie, which indicates the status information
  * between the client agent side and the server side. According to RFC, there
- * are 3 http cookie specifications. This class is compatible with all the three
- * forms. HttpCookie class can accept all these 3 forms of syntax.
+ * are 4 http cookie specifications. This class is compatible with the original
+ * Netscape specification, RFC 2109, RFC 2965 and party compatible with RFC
+ * 6265. HttpCookie class can accept all syntax forms.
  */
 public final class CmisHttpCookie implements Cloneable, Serializable {
 
@@ -94,6 +95,7 @@ public final class CmisHttpCookie implem
         }
         String newDomain = domain.toLowerCase();
         String newHost = host.toLowerCase();
+
         return newDomain.equals(newHost)
                 || (isValidDomain(newDomain) && effDomainMatches(newDomain, newHost)
&& isValidHost(newDomain, newHost));
     }



Mime
View raw message