You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/09/11 06:44:25 UTC
svn commit: r442096 - in
/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata:
GoogleLoginAuthCredentials.java GoogleLoginAuthScheme.java
Author: jmsnell
Date: Sun Sep 10 21:44:25 2006
New Revision: 442096
URL: http://svn.apache.org/viewvc?view=rev&rev=442096
Log:
Provide a GoogleLoginAuthCredentials implementation of the commons client Credentials
interface to make it possible to reuse the gdata auth token for multiple requests.
Added:
incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthCredentials.java
Modified:
incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthScheme.java
Added: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthCredentials.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthCredentials.java?view=auto&rev=442096
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthCredentials.java (added)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthCredentials.java Sun Sep 10 21:44:25 2006
@@ -0,0 +1,61 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.ext.gdata;
+
+import org.apache.commons.httpclient.Credentials;
+
+/**
+ * <p>When using the GoogleLoginAuthScheme with the typical Commons Client
+ * UsernamePasswordCredentials, the AuthScheme implementation will request
+ * a new auth token from the Google server for every request. To make it
+ * a more efficient, clients can use GoogleLoginAuthCredentials which will
+ * perform the Google Auth once to get the auth token which will be reused
+ * for every request.</p>
+ *
+ * <pre>
+ * GoogleLoginAuthScheme.register();
+ *
+ * Client client = new CommonsClient();
+ *
+ * GoogleLoginAuthCredentials credentials =
+ * new GoogleLoginAuthCredentials(
+ * "email", "password", "blogger");
+ * client.addCredentials(
+ * "http://beta.blogger.com",
+ * null, null,
+ * credentials);
+ * </pre>
+ */
+public final class GoogleLoginAuthCredentials
+ implements Credentials {
+
+ private final String auth;
+
+ public GoogleLoginAuthCredentials(String auth) {
+ this.auth = auth;
+ }
+
+ public GoogleLoginAuthCredentials(String id, String pwd, String service) {
+ this.auth = (new GoogleLoginAuthScheme()).getAuth(id, pwd, service);
+ }
+
+ public String getAuth() {
+ return auth;
+ }
+
+}
Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthScheme.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthScheme.java?view=diff&rev=442096&r1=442095&r2=442096
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthScheme.java (original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthScheme.java Sun Sep 10 21:44:25 2006
@@ -76,16 +76,21 @@
Credentials credentials,
HttpMethod method)
throws AuthenticationException {
-
- if (!(credentials instanceof UsernamePasswordCredentials)) {
+ String auth = null;
+ if (credentials instanceof UsernamePasswordCredentials) {
+ UsernamePasswordCredentials usercreds =
+ (UsernamePasswordCredentials) credentials;
+ String id = usercreds.getUserName();
+ String pwd = usercreds.getPassword();
+ auth = getAuth(id, pwd);
+ } else if (credentials instanceof GoogleLoginAuthCredentials) {
+ GoogleLoginAuthCredentials gcreds =
+ (GoogleLoginAuthCredentials) credentials;
+ auth = gcreds.getAuth();
+ } else {
throw new AuthenticationException(
- "Cannot use credentials for GoogleLogin authentication");
+ "Cannot use credentials for GoogleLogin authentication");
}
- UsernamePasswordCredentials usercreds =
- (UsernamePasswordCredentials) credentials;
- String id = usercreds.getUserName();
- String pwd = usercreds.getPassword();
- String auth = getAuth(id, pwd);
StringBuffer buf = new StringBuffer("GoogleLogin ");
buf.append(auth);
return buf.toString();
@@ -115,7 +120,12 @@
return false;
}
- private String getAuth(String id, String pwd) {
+
+ protected String getAuth(String id, String pwd) {
+ return getAuth(id, pwd, service);
+ }
+
+ protected String getAuth(String id, String pwd, String service) {
try {
Client client = new CommonsClient();
Formatter f = new Formatter();
@@ -142,4 +152,10 @@
return null;
}
+ public static String getGoogleLogin(String id, String pwd, String service) {
+ String auth = (new GoogleLoginAuthScheme()).getAuth(id, pwd, service);
+ StringBuffer buf = new StringBuffer("GoogleLogin ");
+ buf.append(auth);
+ return buf.toString();
+ }
}