You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/12/25 16:59:09 UTC

svn commit: r1553395 - /chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java

Author: fmui
Date: Wed Dec 25 15:59:09 2013
New Revision: 1553395

URL: http://svn.apache.org/r1553395
Log:
added OAuth support to SessionParameterMap

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java?rev=1553395&r1=1553394&r2=1553395&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java Wed Dec 25 15:59:09 2013
@@ -267,6 +267,8 @@ public class SessionParameterMap extends
     public void setNoAuthentication() {
         put(SessionParameter.AUTH_HTTP_BASIC, false);
         put(SessionParameter.AUTH_SOAP_USERNAMETOKEN, false);
+
+        remove(SessionParameter.AUTHENTICATION_PROVIDER_CLASS);
     }
 
     /**
@@ -288,6 +290,8 @@ public class SessionParameterMap extends
 
         put(SessionParameter.AUTH_HTTP_BASIC, true);
         put(SessionParameter.AUTH_SOAP_USERNAMETOKEN, false);
+
+        remove(SessionParameter.AUTHENTICATION_PROVIDER_CLASS);
     }
 
     /**
@@ -312,6 +316,8 @@ public class SessionParameterMap extends
 
         put(SessionParameter.AUTH_SOAP_USERNAMETOKEN, true);
         put(SessionParameter.AUTH_HTTP_BASIC, basicAuth);
+
+        remove(SessionParameter.AUTHENTICATION_PROVIDER_CLASS);
     }
 
     /**
@@ -339,8 +345,10 @@ public class SessionParameterMap extends
     }
 
     /**
-     * Turns OAuth 2.0 bearer token authentication on and basic authentication
-     * and UsernameToken authentication off.
+     * Turns simple OAuth 2.0 bearer token authentication on and basic
+     * authentication and UsernameToken authentication off.
+     * <p>
+     * This authentication method does not refresh the token when it expires.
      * 
      * @param token
      *            the bearer token
@@ -356,6 +364,65 @@ public class SessionParameterMap extends
         put(SessionParameter.AUTH_SOAP_USERNAMETOKEN, false);
         put(SessionParameter.AUTH_OAUTH_BEARER, true);
         put(SessionParameter.BREARER_ACCESS_TOKEN, token);
+
+        remove(SessionParameter.AUTHENTICATION_PROVIDER_CLASS);
+    }
+
+    /**
+     * Turns OAuth 2.0 authentication on and basic authentication and
+     * UsernameToken authentication off.
+     * <p>
+     * This authentication method refreshes the token when it expires.
+     * 
+     * @param tokenEntpoint
+     *            the token endpoint URL
+     * @param clientId
+     *            the client ID
+     * @param clientSecret
+     *            the client secret if required, {@code null} otherwise
+     * @param code
+     *            the authorization code
+     * @param redirectUri
+     *            the redirect URI
+     */
+    public void setOAuthAuthentication(String tokenEntpoint, String clientId, String clientSecret, String code,
+            String redirectUri) {
+        if (tokenEntpoint == null) {
+            throw new IllegalArgumentException("Token endpoint must be set!");
+        }
+
+        put(SessionParameter.AUTH_HTTP_BASIC, false);
+        put(SessionParameter.AUTH_SOAP_USERNAMETOKEN, false);
+        put(SessionParameter.AUTH_OAUTH_BEARER, false);
+
+        put(SessionParameter.OAUTH_TOKEN_ENDPOINT, tokenEntpoint);
+
+        if (clientId == null) {
+            remove(SessionParameter.OAUTH_CLIENT_ID);
+        } else {
+            put(SessionParameter.OAUTH_CLIENT_ID, clientId);
+        }
+
+        if (clientSecret == null) {
+            remove(SessionParameter.OAUTH_CLIENT_SECRET);
+        } else {
+            put(SessionParameter.OAUTH_CLIENT_SECRET, clientSecret);
+        }
+
+        if (code == null) {
+            remove(SessionParameter.OAUTH_CODE);
+        } else {
+            put(SessionParameter.OAUTH_CODE, code);
+        }
+
+        if (redirectUri == null) {
+            remove(SessionParameter.OAUTH_REDIRECT_URI);
+        } else {
+            put(SessionParameter.OAUTH_REDIRECT_URI, redirectUri);
+        }
+
+        put(SessionParameter.AUTHENTICATION_PROVIDER_CLASS,
+                "org.apache.chemistry.opencmis.client.bindings.spi.OAuthAuthenticationProvider");
     }
 
     /**