chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1553416 - /chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java
Date Wed, 25 Dec 2013 21:01:57 GMT
Author: fmui
Date: Wed Dec 25 21:01:57 2013
New Revision: 1553416

URL: http://svn.apache.org/r1553416
Log:
more robust OAuth handling

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.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/OAuthAuthenticationProvider.java?rev=1553416&r1=1553415&r2=1553416&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java
Wed Dec 25 21:01:57 2013
@@ -209,15 +209,26 @@ public class OAuthAuthenticationProvider
             throw new CmisConnectionException("Invalid OAuth refresh token!");
         }
 
+        // default expiration time: 1 hour
+        long expiresIn = 3600;
         Object jsonExpiresIn = jsonResponse.get("expires_in");
-        if (jsonExpiresIn != null && !(jsonExpiresIn instanceof Number)) {
-            throw new CmisConnectionException("Invalid OAuth expires in value!");
+        if (jsonExpiresIn != null) {
+            if (jsonExpiresIn instanceof Number) {
+                expiresIn = ((Number) jsonExpiresIn).longValue();
+            } else if (jsonExpiresIn instanceof String) {
+                try {
+                    expiresIn = Long.parseLong((String) jsonExpiresIn);
+                } catch (NumberFormatException nfe) {
+                    throw new CmisConnectionException("Invalid OAuth expires in value!");
+                }
+            } else {
+                throw new CmisConnectionException("Invalid OAuth expires in value!");
+            }
         }
 
         accessToken = jsonAccessToken.toString();
         refreshToken = (jsonRefreshToken == null ? null : jsonRefreshToken.toString());
-        expiresTimestamp = (jsonExpiresIn == null ? 3600 : ((Number) jsonExpiresIn).longValue())
* 1000
-                + System.currentTimeMillis();
+        expiresTimestamp = expiresIn * 1000 + System.currentTimeMillis();
     }
 
     private JSONObject parseResponse(HttpURLConnection conn) {



Mime
View raw message