// Path: google-oauth-client-servlet/src/main/java/com/google/api/client/extensions/auth/helpers/Credential.java
// @Beta
// @Deprecated
// public interface Credential
//     extends HttpRequestInitializer, HttpExecuteInterceptor, HttpUnsuccessfulResponseHandler {
// 
//   /**
//    * Determine if the Credential is no longer valid, after being revoked for example.
//    *
//    * @since 1.5
//    */
//   boolean isInvalid();
// }
// 
// Path: google-oauth-client-servlet/src/main/java/com/google/api/client/extensions/auth/helpers/ThreeLeggedFlow.java
// @Beta
// @Deprecated
// public interface ThreeLeggedFlow {
// 
//   /**
//    * After the object is created, the developer should use this method to interrogate it for the
//    * authorization URL to which the user should be redirected to obtain permission.
//    *
//    * @return URL to which the user should be directed
//    */
//   String getAuthorizationUrl();
// 
//   /** Set {@link HttpTransport} instance for this three legged flow. */
//   void setHttpTransport(HttpTransport transport);
// 
//   /** Set {@link JsonFactory} instance for this three legged flow. */
//   void setJsonFactory(JsonFactory jsonFactory);
// 
//   /**
//    * Convenience function that will load a credential based on the userId for which this flow was
//    * instantiated.
//    *
//    * @param pm {@link PersistenceManager} instance which this flow should use to interact with the
//    *     data store. The caller must remember to call {@link PersistenceManager#close()} after this
//    *     method returns.
//    * @return Fully initialized {@link Credential} object or {@code null} if none exists.
//    */
//   Credential loadCredential(PersistenceManager pm);
// 
//   /**
//    * After the user has authorized the request, the token or code obtained should be passed to this
//    * complete function to allow us to exchange the code with the authentication server for a {@link
//    * Credential}.
//    *
//    * @param authorizationCode Code or token obtained after the user grants permission
//    * @return {@link Credential} object that is obtained from token server
//    */
//   Credential complete(String authorizationCode) throws IOException;
// }


import com.google.api.client.extensions.auth.helpers.Credential;
import com.google.api.client.extensions.auth.helpers.ThreeLeggedFlow;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.Beta;
import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
            throw e;
          }
        }
      } else {
        startAuthFlow(resp, pm, oauthFlow);
      }
    } finally {
      pm.close();
    }
  }

  /**
   * Start the auth flow. Don't run any code after this method that will change the response object.
   */
  private void startAuthFlow(
      HttpServletResponse resp, PersistenceManager pm, ThreeLeggedFlow oauthFlow)
      throws IOException {
    pm.makePersistent(oauthFlow);
    String authorizationUrl = oauthFlow.getAuthorizationUrl();
    resp.sendRedirect(authorizationUrl);
  }

  /**
   * Fetch a credential associated with this request.
   *
   * @param req Request object to use as context for fetching the credential.
   * @return Credential object for this request and user.
   * @since 1.5
   */
  protected Credential getCredential(HttpServletRequest req) {
// Path: google-oauth-client-servlet/src/main/java/com/google/api/client/extensions/auth/helpers/Credential.java
// @Beta
// @Deprecated
// public interface Credential
//     extends HttpRequestInitializer, HttpExecuteInterceptor, HttpUnsuccessfulResponseHandler {
// 
//   /**
//    * Determine if the Credential is no longer valid, after being revoked for example.
//    *
//    * @since 1.5
//    */
//   boolean isInvalid();
// }
// 
// Path: google-oauth-client-servlet/src/main/java/com/google/api/client/extensions/auth/helpers/ThreeLeggedFlow.java
// @Beta
// @Deprecated
// public interface ThreeLeggedFlow {
// 
//   /**
//    * After the object is created, the developer should use this method to interrogate it for the
//    * authorization URL to which the user should be redirected to obtain permission.
//    *
//    * @return URL to which the user should be directed
//    */
//   String getAuthorizationUrl();
// 
//   /** Set {@link HttpTransport} instance for this three legged flow. */
//   void setHttpTransport(HttpTransport transport);
// 
//   /** Set {@link JsonFactory} instance for this three legged flow. */
//   void setJsonFactory(JsonFactory jsonFactory);
// 
//   /**
//    * Convenience function that will load a credential based on the userId for which this flow was
//    * instantiated.
//    *
//    * @param pm {@link PersistenceManager} instance which this flow should use to interact with the
//    *     data store. The caller must remember to call {@link PersistenceManager#close()} after this
//    *     method returns.
//    * @return Fully initialized {@link Credential} object or {@code null} if none exists.
//    */
//   Credential loadCredential(PersistenceManager pm);
// 
//   /**
//    * After the user has authorized the request, the token or code obtained should be passed to this
//    * complete function to allow us to exchange the code with the authentication server for a {@link
//    * Credential}.
//    *
//    * @param authorizationCode Code or token obtained after the user grants permission
//    * @return {@link Credential} object that is obtained from token server
//    */
//   Credential complete(String authorizationCode) throws IOException;
// }


// Path: google-oauth-client-servlet/src/main/java/com/google/api/client/extensions/servlet/auth/AbstractFlowUserServlet.java
import com.google.api.client.extensions.auth.helpers.Credential;
import com.google.api.client.extensions.auth.helpers.ThreeLeggedFlow;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.Beta;
import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

            throw e;
          }
        }
      } else {
        startAuthFlow(resp, pm, oauthFlow);
      }
    } finally {
      pm.close();
    }
  }

  /**
   * Start the auth flow. Don't run any code after this method that will change the response object.
   */
  private void startAuthFlow(
      HttpServletResponse resp, PersistenceManager pm, ThreeLeggedFlow oauthFlow)
      throws IOException {
    pm.makePersistent(oauthFlow);
    String authorizationUrl = oauthFlow.getAuthorizationUrl();
    resp.sendRedirect(authorizationUrl);
  }

  /**
   * Fetch a credential associated with this request.
   *
   * @param req Request object to use as context for fetching the credential.
   * @return Credential object for this request and user.
   * @since 1.5
   */
  protected Credential getCredential(HttpServletRequest req) {
    Credential cred = (Credential) req.getAttribute(AUTH_CREDENTIAL);