diff options
author | Patrick Flynn <paflynn@google.com> | 2014-10-16 12:41:31 -0400 |
---|---|---|
committer | Patrick Flynn <paflynn@google.com> | 2014-10-16 13:35:44 -0400 |
commit | c4a3cf483fcd3c5da8ea258f29dd7b9527923836 (patch) | |
tree | 26fce5ce2c2b3812cc586d6eb0ba08e7c7000946 | |
parent | 32f0f46af834c09bcd98a082826b03f5d132b6a9 (diff) | |
download | login-c4a3cf483fcd3c5da8ea258f29dd7b9527923836.tar.gz |
Changed the login CancellableServerReceiver to handle cancelled logins with a RequestCancelledException so that GoogleLogin doesn't treat them like errors.
Change-Id: Id9b5188a372722dabef0e2858e063b160e82dd9f
-rw-r--r-- | src/com/google/gct/login/CancellableServerReceiver.java | 11 | ||||
-rw-r--r-- | src/com/google/gct/login/GoogleLogin.java | 6 | ||||
-rw-r--r-- | src/com/google/gct/login/RequestCancelledException.java | 24 |
3 files changed, 37 insertions, 4 deletions
diff --git a/src/com/google/gct/login/CancellableServerReceiver.java b/src/com/google/gct/login/CancellableServerReceiver.java index ada3a51..c0e894b 100644 --- a/src/com/google/gct/login/CancellableServerReceiver.java +++ b/src/com/google/gct/login/CancellableServerReceiver.java @@ -25,7 +25,6 @@ import com.google.api.client.repackaged.org.mortbay.jetty.handler.AbstractHandle import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.PrintWriter; import java.net.Socket; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; @@ -36,6 +35,7 @@ import java.util.concurrent.locks.ReentrantLock; */ class CancellableServerReceiver implements VerificationCodeReceiver { private static final String CALLBACK_PATH = "/Callback"; + public static final String REQUEST_CANCELLED_STRING = "Request cancelled."; /** Server or {@code null} before {@link #getRedirectUri()}. */ private Server server; @@ -100,13 +100,18 @@ class CancellableServerReceiver implements VerificationCodeReceiver { } @Override - public String waitForCode() throws IOException { + public String waitForCode() throws IOException, RequestCancelledException { lock.lock(); try { while (code == null && error == null) { gotAuthorizationResponse.awaitUninterruptibly(); } if (error != null) { + // If the user cancels the request from Studio (Request Cancelled.), or they cancel the request from the auth page ('access_denied') + // then return null and let the UI handle the cancellation. + if (error.equals(REQUEST_CANCELLED_STRING) || error.equals("access_denied")) { + throw new RequestCancelledException(); + } throw new IOException("User authorization failed (" + error + ")"); } return code; @@ -126,7 +131,7 @@ class CancellableServerReceiver implements VerificationCodeReceiver { } lock.lock(); try { - error = "Request cancelled."; + error = REQUEST_CANCELLED_STRING; code = null; gotAuthorizationResponse.signal(); } diff --git a/src/com/google/gct/login/GoogleLogin.java b/src/com/google/gct/login/GoogleLogin.java index 4676152..4706947 100644 --- a/src/com/google/gct/login/GoogleLogin.java +++ b/src/com/google/gct/login/GoogleLogin.java @@ -615,8 +615,12 @@ public class GoogleLogin { try { verificationCode = receiver.waitForCode(); } + catch (RequestCancelledException e) { + GoogleLoginUtils.showErrorDialog("Login cancelled.", "Google Login"); + return null; + } catch (IOException e) { - logErrorAndDisplayDialog(title == null? "Google Login" : title, e); + logErrorAndDisplayDialog(title == null ? "Google Login" : title, e); return null; } finally { diff --git a/src/com/google/gct/login/RequestCancelledException.java b/src/com/google/gct/login/RequestCancelledException.java new file mode 100644 index 0000000..f32c556 --- /dev/null +++ b/src/com/google/gct/login/RequestCancelledException.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * 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.gct.login; + +import java.io.IOException; + +/** + * An exception that indicates that the login request was cancelled by the user. + */ +class RequestCancelledException extends IOException { +} |