diff --git a/clirr-ignored-differences.xml b/clirr-ignored-differences.xml index 114008428..a4a93043c 100644 --- a/clirr-ignored-differences.xml +++ b/clirr-ignored-differences.xml @@ -2,4 +2,8 @@ + + 8001 + com/google/api/client/googleapis/auth/clientlogin/** + diff --git a/findbugs-exclude.xml b/findbugs-exclude.xml index 779eef93d..fb145e8f9 100644 --- a/findbugs-exclude.xml +++ b/findbugs-exclude.xml @@ -6,23 +6,18 @@ - - - - - - - + + - + - + @@ -88,26 +83,26 @@ - - + + - - + + - - + + - - + + - - + + diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/AuthKeyValueParser.java b/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/AuthKeyValueParser.java deleted file mode 100644 index 4dacf441e..000000000 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/AuthKeyValueParser.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2010 Google Inc. - * - * Licensed 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 com.google.api.client.googleapis.auth.clientlogin; - -import com.google.api.client.http.HttpResponse; -import com.google.api.client.util.Beta; -import com.google.api.client.util.ClassInfo; -import com.google.api.client.util.FieldInfo; -import com.google.api.client.util.GenericData; -import com.google.api.client.util.ObjectParser; -import com.google.api.client.util.Types; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.Field; -import java.lang.reflect.Type; -import java.nio.charset.Charset; -import java.util.Map; - -/** - * {@link Beta}
- * HTTP parser for Google response to an Authorization request. - * - * @since 1.10 - * @author Yaniv Inbar - */ -@Beta -final class AuthKeyValueParser implements ObjectParser { - - /** Singleton instance. */ - public static final AuthKeyValueParser INSTANCE = new AuthKeyValueParser(); - - public String getContentType() { - return "text/plain"; - } - - public T parse(HttpResponse response, Class dataClass) throws IOException { - response.setContentLoggingLimit(0); - InputStream content = response.getContent(); - try { - return parse(content, dataClass); - } finally { - content.close(); - } - } - - public T parse(InputStream content, Class dataClass) throws IOException { - ClassInfo classInfo = ClassInfo.of(dataClass); - T newInstance = Types.newInstance(dataClass); - BufferedReader reader = new BufferedReader(new InputStreamReader(content)); - while (true) { - String line = reader.readLine(); - if (line == null) { - break; - } - int equals = line.indexOf('='); - String key = line.substring(0, equals); - String value = line.substring(equals + 1); - // get the field from the type information - Field field = classInfo.getField(key); - if (field != null) { - Class fieldClass = field.getType(); - Object fieldValue; - if (fieldClass == boolean.class || fieldClass == Boolean.class) { - fieldValue = Boolean.valueOf(value); - } else { - fieldValue = value; - } - FieldInfo.setFieldValue(field, newInstance, fieldValue); - } else if (GenericData.class.isAssignableFrom(dataClass)) { - GenericData data = (GenericData) newInstance; - data.set(key, value); - } else if (Map.class.isAssignableFrom(dataClass)) { - @SuppressWarnings("unchecked") - Map map = (Map) newInstance; - map.put(key, value); - } - } - - return newInstance; - } - - private AuthKeyValueParser() { - } - - public T parseAndClose(InputStream in, Charset charset, Class dataClass) - throws IOException { - Reader reader = new InputStreamReader(in, charset); - return parseAndClose(reader, dataClass); - } - - public Object parseAndClose(InputStream in, Charset charset, Type dataType) { - throw new UnsupportedOperationException( - "Type-based parsing is not yet supported -- use Class instead"); - } - - public T parseAndClose(Reader reader, Class dataClass) throws IOException { - try { - ClassInfo classInfo = ClassInfo.of(dataClass); - T newInstance = Types.newInstance(dataClass); - BufferedReader breader = new BufferedReader(reader); - while (true) { - String line = breader.readLine(); - if (line == null) { - break; - } - int equals = line.indexOf('='); - String key = line.substring(0, equals); - String value = line.substring(equals + 1); - // get the field from the type information - Field field = classInfo.getField(key); - if (field != null) { - Class fieldClass = field.getType(); - Object fieldValue; - if (fieldClass == boolean.class || fieldClass == Boolean.class) { - fieldValue = Boolean.valueOf(value); - } else { - fieldValue = value; - } - FieldInfo.setFieldValue(field, newInstance, fieldValue); - } else if (GenericData.class.isAssignableFrom(dataClass)) { - GenericData data = (GenericData) newInstance; - data.set(key, value); - } else if (Map.class.isAssignableFrom(dataClass)) { - @SuppressWarnings("unchecked") - Map map = (Map) newInstance; - map.put(key, value); - } - } - - return newInstance; - } finally { - reader.close(); - } - } - - public Object parseAndClose(Reader reader, Type dataType) { - throw new UnsupportedOperationException( - "Type-based parsing is not yet supported -- use Class instead"); - } -} diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLogin.java b/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLogin.java deleted file mode 100644 index 06a96c752..000000000 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLogin.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2010 Google Inc. - * - * Licensed 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 com.google.api.client.googleapis.auth.clientlogin; - -import com.google.api.client.http.GenericUrl; -import com.google.api.client.http.HttpExecuteInterceptor; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; -import com.google.api.client.http.HttpResponse; -import com.google.api.client.http.HttpResponseException; -import com.google.api.client.http.HttpTransport; -import com.google.api.client.http.UrlEncodedContent; -import com.google.api.client.util.Beta; -import com.google.api.client.util.Key; -import com.google.api.client.util.StringUtils; -import com.google.api.client.util.Strings; - -import java.io.IOException; - -/** - * {@link Beta}
- * Client Login authentication method as described in ClientLogin for - * Installed Applications. - * - * @since 1.0 - * @author Yaniv Inbar - */ -@Beta -public final class ClientLogin { - - /** - * HTTP transport required for executing request in {@link #authenticate()}. - * - * @since 1.3 - */ - public HttpTransport transport; - - /** - * URL for the Client Login authorization server. - * - *

- * By default this is {@code "https://www.google.com"}, but it may be overridden for testing - * purposes. - *

- * - * @since 1.3 - */ - public GenericUrl serverUrl = new GenericUrl("https://www.google.com"); - - /** - * Short string identifying your application for logging purposes of the form: - * "companyName-applicationName-versionID". - */ - @Key("source") - public String applicationName; - - /** - * Name of the Google service you're requesting authorization for, for example {@code "cl"} for - * Google Calendar. - */ - @Key("service") - public String authTokenType; - - /** User's full email address. */ - @Key("Email") - public String username; - - /** User's password. */ - @Key("Passwd") - public String password; - - /** - * Type of account to request authorization for. Possible values are: - * - *
    - *
  • GOOGLE (get authorization for a Google account only)
  • - *
  • HOSTED (get authorization for a hosted account only)
  • - *
  • HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get - * authorization for a Google account)
  • - *
- * - * Use HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If - * the user information matches both a hosted and a Google account, only the hosted account is - * authorized. - * - * @since 1.1 - */ - @Key - public String accountType; - - /** (optional) Token representing the specific CAPTCHA challenge. */ - @Key("logintoken") - public String captchaToken; - - /** (optional) String entered by the user as an answer to a CAPTCHA challenge. */ - @Key("logincaptcha") - public String captchaAnswer; - - /** - * Key/value data to parse a success response. - * - *

- * Sample usage, taking advantage that this class implements {@link HttpRequestInitializer}: - *

- * - *
-    public static HttpRequestFactory createRequestFactory(
-        HttpTransport transport, Response response) {
-      return transport.createRequestFactory(response);
-    }
-   * 
- * - *

- * If you have a custom request initializer, take a look at the sample usage for - * {@link HttpExecuteInterceptor}, which this class also implements. - *

- */ - public static final class Response implements HttpExecuteInterceptor, HttpRequestInitializer { - - /** Authentication token. */ - @Key("Auth") - public String auth; - - /** Returns the authorization header value to use based on the authentication token. */ - public String getAuthorizationHeaderValue() { - return ClientLogin.getAuthorizationHeaderValue(auth); - } - - public void initialize(HttpRequest request) { - request.setInterceptor(this); - } - - public void intercept(HttpRequest request) { - request.getHeaders().setAuthorization(getAuthorizationHeaderValue()); - } - } - - /** Key/value data to parse an error response. */ - public static final class ErrorInfo { - - @Key("Error") - public String error; - - @Key("Url") - public String url; - - @Key("CaptchaToken") - public String captchaToken; - - @Key("CaptchaUrl") - public String captchaUrl; - } - - /** - * Authenticates based on the provided field values. - * - * @throws ClientLoginResponseException if the authentication response has an error code, such as - * for a CAPTCHA challenge. - */ - public Response authenticate() throws IOException { - GenericUrl url = serverUrl.clone(); - url.appendRawPath("/accounts/ClientLogin"); - HttpRequest request = - transport.createRequestFactory().buildPostRequest(url, new UrlEncodedContent(this)); - request.setParser(AuthKeyValueParser.INSTANCE); - request.setContentLoggingLimit(0); - request.setThrowExceptionOnExecuteError(false); - HttpResponse response = request.execute(); - // check for an HTTP success response (2xx) - if (response.isSuccessStatusCode()) { - return response.parseAs(Response.class); - } - HttpResponseException.Builder builder = new HttpResponseException.Builder( - response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); - // On error, throw a ClientLoginResponseException with the parsed error details - ErrorInfo details = response.parseAs(ErrorInfo.class); - String detailString = details.toString(); - StringBuilder message = HttpResponseException.computeMessageBuffer(response); - if (!Strings.isNullOrEmpty(detailString)) { - message.append(StringUtils.LINE_SEPARATOR).append(detailString); - builder.setContent(detailString); - } - builder.setMessage(message.toString()); - throw new ClientLoginResponseException(builder, details); - } - - /** - * Returns Google Login {@code "Authorization"} header value based on the given authentication - * token. - * - * @since 1.13 - */ - public static String getAuthorizationHeaderValue(String authToken) { - return "GoogleLogin auth=" + authToken; - } -} diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLoginResponseException.java b/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLoginResponseException.java deleted file mode 100644 index b6d74f549..000000000 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLoginResponseException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2011 Google Inc. - * - * Licensed 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 com.google.api.client.googleapis.auth.clientlogin; - -import com.google.api.client.googleapis.auth.clientlogin.ClientLogin.ErrorInfo; -import com.google.api.client.http.HttpResponseException; -import com.google.api.client.util.Beta; - -/** - * {@link Beta}
- * Exception thrown when an error status code is detected in an HTTP response to a Google - * ClientLogin request in {@link ClientLogin} . - * - *

- * To get the structured details, use {@link #getDetails()}. - *

- * - * @since 1.7 - * @author Yaniv Inbar - */ -@Beta -public class ClientLoginResponseException extends HttpResponseException { - - private static final long serialVersionUID = 4974317674023010928L; - - /** Error details or {@code null} for none. */ - private final transient ErrorInfo details; - - /** - * @param builder builder - * @param details error details or {@code null} for none - */ - ClientLoginResponseException(Builder builder, ErrorInfo details) { - super(builder); - this.details = details; - } - - /** Return the error details or {@code null} for none. */ - public final ErrorInfo getDetails() { - return details; - } -} diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/package-info.java b/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/package-info.java deleted file mode 100644 index 316a58b47..000000000 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2010 Google Inc. - * - * Licensed 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. - */ - -/** - * {@link com.google.api.client.util.Beta}
- * Google's legacy ClientLogin authentication method as described in ClientLogin for - * Installed Applications. - * - * @since 1.0 - * @author Yaniv Inbar - */ -@com.google.api.client.util.Beta -package com.google.api.client.googleapis.auth.clientlogin; - diff --git a/pom.xml b/pom.xml index 42800549c..a4791b0f7 100644 --- a/pom.xml +++ b/pom.xml @@ -481,7 +481,7 @@ org.codehaus.mojo clirr-maven-plugin - 1.19.0 + 1.27.0 ${basedir}/../clirr-ignored-differences.xml true