[alfresco-opencmis-extension] r19 committed - Changed OpenCMIS dependency, improvement to OAuth auth provider so tha...

17 views
Skip to first unread message

alfresco-opencmis-exte...@codespot.com

unread,
Oct 30, 2012, 4:38:24 PM10/30/12
to alfresco-opencmis...@googlegroups.com
Revision: 19
Author: steven...@gmail.com
Date: Tue Oct 30 12:25:57 2012
Log: Changed OpenCMIS dependency, improvement to OAuth auth provider
so that it can be used in OpenCMIS Workbench
http://code.google.com/a/apache-extras.org/p/alfresco-opencmis-extension/source/detail?r=19

Modified:
/trunk/pom.xml

/trunk/src/main/java/org/alfresco/cmis/client/authentication/OAuthCMISAuthenticationProvider.java

=======================================
--- /trunk/pom.xml Tue Oct 2 06:18:15 2012
+++ /trunk/pom.xml Tue Oct 30 12:25:57 2012
@@ -20,7 +20,7 @@
<groupId>org.alfresco.cmis.client</groupId>
<artifactId>alfresco-opencmis-extension</artifactId>
<name>Alfresco OpenCMIS Extension</name>
- <version>0.4-SNAPSHOT</version>
+ <version>0.4</version>
<packaging>jar</packaging>

<organization>
@@ -127,6 +127,30 @@
<workspace>..</workspace>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>

@@ -134,22 +158,22 @@
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-impl</artifactId>
- <version>0.7.0</version>
+ <version>0.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-api</artifactId>
- <version>0.7.0</version>
+ <version>0.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-commons-impl</artifactId>
- <version>0.7.0</version>
+ <version>0.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-commons-api</artifactId>
- <version>0.7.0</version>
+ <version>0.8.0</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/authentication/OAuthCMISAuthenticationProvider.java
Tue Oct 2 06:11:01 2012
+++
/trunk/src/main/java/org/alfresco/cmis/client/authentication/OAuthCMISAuthenticationProvider.java
Tue Oct 30 12:25:57 2012
@@ -34,14 +34,23 @@
/**
* An OpenCMIS OAuth authentication provider.
*
+ * Example connection parameters:
+ *
+ * org.apache.chemistry.opencmis.binding.spi.type=atompub
+ *
org.apache.chemistry.opencmis.binding.atompub.url=https://api.alfresco.com/cmis/versions/1.0/atom
+ *
org.apache.chemistry.opencmis.binding.auth.classname=org.alfresco.cmis.client.authentication.OAuthCMISAuthenticationProvider
+ * org.apache.chemistry.opencmis.binding.auth.http.basic=false
+ * org.apache.chemistry.opencmis.binding.auth.oauth.accessToken=<access
token>
+ * org.apache.chemistry.opencmis.binding.compression=true
+ *
* @author steveglover
*
*/
public class OAuthCMISAuthenticationProvider extends
AbstractAuthenticationProvider
{
- public static final int ALFRESCO_ACCESS_TOKEN_TIMEOUT = 60 * 60 * 1000;
public static final String ALFRESCO_ACCESS_TOKEN_URL
= "https://api.alfresco.com/auth/oauth/versions/2/token";
public static final String ALFRESCO_REFRESH_TOKEN_URL
= "https://api.alfresco.com/auth/oauth/versions/2/token";
+ public static final String PARAM_ACCESS_TOKEN
= "org.apache.chemistry.opencmis.binding.auth.oauth.accessToken";

private static final long serialVersionUID = 1L;

@@ -73,6 +82,10 @@
{
return new OAuthCMISAuthenticationProvider(clientId, clientSecret,
redirectUrl, ALFRESCO_ACCESS_TOKEN_URL, ALFRESCO_REFRESH_TOKEN_URL,
authCode);
}
+
+ public OAuthCMISAuthenticationProvider()
+ {
+ }

/**
* Authenticates with the Alfresco CMIS Public Api with a
previously-generated access token (no refresh token support).
@@ -109,7 +122,7 @@
// Create the client
client = new HttpClient(manager);

- getAccessToken();
+ generateAccessToken();
}

public AccessToken getAccessTokenData()
@@ -117,7 +130,7 @@
return accessTokenData;
}

- private void getAccessToken()
+ private void generateAccessToken()
{
PostMethod method = new PostMethod(accessTokenUrl);
NameValuePair[] data =
@@ -212,10 +225,25 @@
cookieManager = new CmisCookieManager();
}
}
+
+ private String getAccessToken()
+ {
+ Object accessTokenObject = getSession().get(PARAM_ACCESS_TOKEN);
+ if (accessTokenObject instanceof String) {
+ return (String) accessTokenObject;
+ }
+
+ return null;
+ }

@Override
public Map<String, List<String>> getHTTPHeaders(String url) {
Map<String, List<String>> result = new HashMap<String,
List<String>>(fixedHeaders);
+
+ if(accessToken == null)
+ {
+ accessToken = getAccessToken();
+ }

if(accessToken == null)
{
@@ -380,7 +408,7 @@
this.accessToken = (String)json.get("access_token");
this.tokenType = (String)json.get("token_type");
Long expiresIn = (Long)json.get("expires_in");
- this.expiresAt = System.currentTimeMillis() + expiresIn *
ALFRESCO_ACCESS_TOKEN_TIMEOUT;
+ this.expiresAt = System.currentTimeMillis() + expiresIn * 60 * 60 *
1000;
this.refreshToken = (String)json.get("refresh_token");
this.scope = (String)json.get("scope");
}
@@ -391,7 +419,7 @@
this.accessToken = accessToken;
this.tokenType = tokenType;
Long expires = expiresIn;
- this.expiresAt = System.currentTimeMillis() + expires *
ALFRESCO_ACCESS_TOKEN_TIMEOUT;
+ this.expiresAt = System.currentTimeMillis() + expires * 60 * 60 *
1000;
this.refreshToken = refreshToken;
this.scope = scope;
}
Reply all
Reply to author
Forward
0 new messages