nl.topicus.jdbc.shaded.com.google.auth.oauth2.OAuth2Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spanner-jdbc Show documentation
Show all versions of spanner-jdbc Show documentation
JDBC Driver for Google Cloud Spanner
/*
* Copyright 2015, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package nl.topicus.jdbc.shaded.com.google.auth.oauth2;
import nl.topicus.jdbc.shaded.com.google.api.client.http.HttpHeaders;
import nl.topicus.jdbc.shaded.com.google.api.client.http.HttpTransport;
import nl.topicus.jdbc.shaded.com.google.api.client.http.javanet.NetHttpTransport;
import nl.topicus.jdbc.shaded.com.google.api.client.json.GenericJson;
import nl.topicus.jdbc.shaded.com.google.api.client.json.JsonFactory;
import nl.topicus.jdbc.shaded.com.google.api.client.json.JsonObjectParser;
import nl.topicus.jdbc.shaded.com.google.api.client.json.jackson2.JacksonFactory;
import nl.topicus.jdbc.shaded.com.google.auth.http.AuthHttpConstants;
import nl.topicus.jdbc.shaded.com.google.auth.http.HttpTransportFactory;
import java.nl.topicus.jdbc.shaded.io.ByteArrayInputStream;
import java.nl.topicus.jdbc.shaded.io.IOException;
import java.nl.topicus.jdbc.shaded.io.InputStream;
import java.math.BigDecimal;
import java.nl.topicus.jdbc.shaded.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
/**
* Internal utilities for the nl.topicus.jdbc.shaded.com.google.auth.oauth2 namespace.
*/
class OAuth2Utils {
static final String SIGNATURE_ALGORITHM = "SHA256withRSA";
static final URI TOKEN_SERVER_URI = URI.create("https://accounts.google.nl.topicus.jdbc.shaded.com.o/oauth2/token");
static final URI TOKEN_REVOKE_URI = URI.create("https://accounts.google.nl.topicus.jdbc.shaded.com.o/oauth2/revoke");
static final URI USER_AUTH_URI = URI.create("https://accounts.google.nl.topicus.jdbc.shaded.com.o/oauth2/auth");
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
static final HttpTransportFactory HTTP_TRANSPORT_FACTORY = new DefaultHttpTransportFactory();
static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
static final Charset UTF_8 = Charset.forName("UTF-8");
private static String VALUE_NOT_FOUND_MESSAGE = "%sExpected value %s not found.";
private static String VALUE_WRONG_TYPE_MESSAGE = "%sExpected %s value %s of wrong type.";
static final String BEARER_PREFIX = AuthHttpConstants.BEARER + " ";
static class DefaultHttpTransportFactory implements HttpTransportFactory {
public HttpTransport create() {
return HTTP_TRANSPORT;
}
}
/**
* Returns whether the headers contain the specified value as one of the entries in the
* specified header.
*/
static boolean headersContainValue(HttpHeaders headers, String headerName, String value) {
Object values = headers.get(headerName);
if (values instanceof Collection) {
@SuppressWarnings("unchecked")
Collection