Author: fmui
Date: Sat May 7 22:28:13 2011
New Revision: 1100643
URL: http://svn.apache.org/viewvc?rev=1100643&view=rev
Log:
added cookie-aware authentication provider
Added:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/CookieAwareStandardAuthenticationProvider.java-6
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/AuthenticationProvider.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.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/AbstractAuthenticationProvider.java?rev=1100643&r1=1100642&r2=1100643&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java Sat May 7 22:28:13 2011
@@ -57,7 +57,7 @@ public abstract class AbstractAuthentica
return null;
}
- public void setResponseHeaders(String url, Map<String, List<String>> headers) {
+ public void putResponseHeaders(String url, Map<String, List<String>> headers) {
}
/**
Added: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/CookieAwareStandardAuthenticationProvider.java-6
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/CookieAwareStandardAuthenticationProvider.java-6?rev=1100643&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/CookieAwareStandardAuthenticationProvider.java-6 (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/CookieAwareStandardAuthenticationProvider.java-6 Sat May 7 22:28:13 2011
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.bindings.spi;
+
+import java.net.CookieManager;
+import java.net.CookiePolicy;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
+
+/**
+ * Standard authentication provider class with cookie support.
+ *
+ * (This class uses Java 6 classes and therefore is not part of OpenCMIS
+ * releases.)
+ */
+public class CookieAwareStandardAuthenticationProvider extends StandardAuthenticationProvider {
+
+ private static final long serialVersionUID = 1L;
+
+ private final CookieManager cookies = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
+
+ @Override
+ public Map<String, List<String>> getHTTPHeaders(String url) {
+ Map<String, List<String>> headers = super.getHTTPHeaders(url);
+ if (headers == null) {
+ headers = new HashMap<String, List<String>>();
+ }
+
+ try {
+ headers.putAll(cookies.get(new URI(url), headers));
+ } catch (Exception e) {
+ throw new CmisConnectionException("Cannot get cookies: " + e.getMessage(), e);
+ }
+
+ return headers;
+ }
+
+ @Override
+ public void putResponseHeaders(String url, Map<String, List<String>> headers) {
+ try {
+ cookies.put(new URI(url), headers);
+ } catch (Exception e) {
+ throw new CmisConnectionException("Cannot set cookies: " + e.getMessage(), e);
+ }
+ }
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.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/atompub/HttpUtils.java?rev=1100643&r1=1100642&r2=1100643&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java Sat May 7 22:28:13 2011
@@ -190,7 +190,7 @@ public class HttpUtils {
// forward response HTTP headers
if (authProvider != null) {
- authProvider.setResponseHeaders(url.toString(), conn.getHeaderFields());
+ authProvider.putResponseHeaders(url.toString(), conn.getHeaderFields());
}
// get the response
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.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/webservices/AbstractPortProvider.java?rev=1100643&r1=1100642&r2=1100643&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java Sat May 7 22:28:13 2011
@@ -148,7 +148,7 @@ public abstract class AbstractPortProvid
@SuppressWarnings("unchecked")
Map<String, List<String>> headers = (Map<String, List<String>>) bp.getResponseContext().get(
MessageContext.HTTP_RESPONSE_HEADERS);
- authProvider.setResponseHeaders(url, headers);
+ authProvider.putResponseHeaders(url, headers);
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/AuthenticationProvider.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/AuthenticationProvider.java?rev=1100643&r1=1100642&r2=1100643&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/AuthenticationProvider.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/AuthenticationProvider.java Sat May 7 22:28:13 2011
@@ -58,5 +58,5 @@ public interface AuthenticationProvider
* @param headers
* the HTTP headers
*/
- void setResponseHeaders(String url, Map<String, List<String>> headers);
+ void putResponseHeaders(String url, Map<String, List<String>> headers);
}