Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: switch to GSON per security team advice #586

Merged
merged 8 commits into from Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -49,7 +49,7 @@
* com.google.api.client.extensions.appengine.auth.oauth2.AbstractAppEngineAuthorizationCodeCallbackServlet}.
*
* <p>Upgrade warning: in version 1.15 there was an implementation of {@link
* #newJsonFactoryInstance()} that used {@code com.google.api.client.json.jackson.JacksonFactory},
* #newJsonFactoryInstance()} that used {@code com.google.api.client.json.jackson.GsonFactory},
* but starting with version 1.16 there is no such implementation.
*
* @author moshenko@google.com (Jacob Moshenko)
Expand Down
Expand Up @@ -30,7 +30,7 @@
* com.google.api.client.extensions.appengine.auth.oauth2.AbstractAppEngineAuthorizationCodeServlet}.
*
* <p>Upgrade warning: in version 1.15 there was an implementation of {@link
* #newJsonFactoryInstance()} that used {@code com.google.api.client.json.jackson.JacksonFactory},
* #newJsonFactoryInstance()} that used {@code com.google.api.client.json.jackson.GsonFactory},
* but starting with version 1.16 there is no such implementation.
*
* @author moshenko@google.com (Jacob Moshenko)
Expand Down
Expand Up @@ -70,7 +70,7 @@
* protected AuthorizationCodeFlow initializeFlow() throws IOException {
* return new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),
* new UrlFetchTransport(),
* new JacksonFactory(),
* new GsonFactory(),
* new GenericUrl("https://server.example.com/token"),
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw"),
* "s6BhdRkqt3",
Expand Down
Expand Up @@ -63,7 +63,7 @@
* protected AuthorizationCodeFlow initializeFlow() throws IOException {
* return new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),
* new UrlFetchTransport(),
* new JacksonFactory(),
* new GsonFactory(),
* new GenericUrl("https://server.example.com/token"),
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw"),
* "s6BhdRkqt3",
Expand Down
2 changes: 1 addition & 1 deletion google-oauth-client-java6/pom.xml
Expand Up @@ -92,7 +92,7 @@
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<artifactId>google-http-client-gson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -25,7 +25,7 @@
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonGenerator;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
Expand All @@ -48,7 +48,7 @@
@Deprecated
public class FileCredentialStoreTest extends TestCase {

static final JsonFactory JSON_FACTORY = new JacksonFactory();
static final JsonFactory JSON_FACTORY = new GsonFactory();
private static final String ACCESS_TOKEN = "abc";
static final String NEW_ACCESS_TOKEN = "def";
private static final GenericUrl TOKEN_SERVER_URL = new GenericUrl("http://example.com/token");
Expand Down
Expand Up @@ -137,7 +137,7 @@ protected final HttpTransport getHttpTransport() {
* json factory and should be as simple as:
*
* <pre>
* new JacksonFactory();
* new GsonFactory();
* </pre>
*
* @return {@link JsonFactory} instance for your particular environment
Expand Down
Expand Up @@ -168,7 +168,7 @@ protected final HttpTransport getHttpTransport() {
* json factory and should be as simple as:
*
* <pre>
* new JacksonFactory();
* new GsonFactory();
* </pre>
*
* @return {@link JsonFactory} instance for your particular environment
Expand Down
Expand Up @@ -67,7 +67,7 @@
* protected AuthorizationCodeFlow initializeFlow() throws IOException {
* return new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),
* new NetHttpTransport(),
* new JacksonFactory(),
* new GsonFactory(),
* new GenericUrl("https://server.example.com/token"),
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw"),
* "s6BhdRkqt3",
Expand Down
Expand Up @@ -69,7 +69,7 @@
* protected AuthorizationCodeFlow initializeFlow() throws IOException {
* return new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),
* new NetHttpTransport(),
* new JacksonFactory(),
* new GsonFactory(),
* new GenericUrl("https://server.example.com/token"),
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw"),
* "s6BhdRkqt3",
Expand Down
2 changes: 1 addition & 1 deletion google-oauth-client/pom.xml
Expand Up @@ -81,7 +81,7 @@
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<artifactId>google-http-client-gson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -38,7 +38,7 @@
* static void requestAccessToken() throws IOException {
* try {
* TokenResponse response =
* new AuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),
* new AuthorizationCodeTokenRequest(new NetHttpTransport(), new GsonFactory(),
* new GenericUrl("https://server.example.com/token"), "SplxlOBeZQQYbYS6WxSbIA")
* .setRedirectUri("https://client.example.com/rd")
* .setClientAuthentication(
Expand Down
Expand Up @@ -36,7 +36,7 @@
* static void requestAccessToken() throws IOException {
* try {
* TokenResponse response =
* new ClientCredentialsTokenRequest(new NetHttpTransport(), new JacksonFactory(),
* new ClientCredentialsTokenRequest(new NetHttpTransport(), new GsonFactory(),
* new GenericUrl("https://server.example.com/token"))
* .setRedirectUri("https://client.example.com/rd")
* .setClientAuthentication(
Expand Down
Expand Up @@ -37,7 +37,7 @@
* static void requestAccessToken() throws IOException {
* try {
* TokenResponse response = new AuthorizationCodeTokenRequest(new NetHttpTransport(),
* new JacksonFactory(), new GenericUrl("https://server.example.com/token"),
* new GsonFactory(), new GenericUrl("https://server.example.com/token"),
* "SplxlOBeZQQYbYS6WxSbIA").setRedirectUri("https://client.example.com/rd")
* .setClientAuthentication(
* new ClientParametersAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw")).execute();
Expand Down
Expand Up @@ -39,7 +39,7 @@
* static void requestAccessToken() throws IOException {
* try {
* TokenResponse response =
* new PasswordTokenRequest(new NetHttpTransport(), new JacksonFactory(),
* new PasswordTokenRequest(new NetHttpTransport(), new GsonFactory(),
* new GenericUrl("https://server.example.com/token"), "johndoe", "A3ddj3w")
* .setRedirectUri("https://client.example.com/rd")
* .setClientAuthentication(
Expand Down
Expand Up @@ -38,7 +38,7 @@
* static void refreshAccessToken() throws IOException {
* try {
* TokenResponse response =
* new RefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(), new GenericUrl(
* new RefreshTokenRequest(new NetHttpTransport(), new GsonFactory(), new GenericUrl(
* "https://server.example.com/token"), "tGzv3JOkF0XG5Qx2TlKWIA")
* .setClientAuthentication(
* new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw")).execute();
Expand Down
Expand Up @@ -19,7 +19,7 @@
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
Expand All @@ -34,7 +34,7 @@
*/
public abstract class AuthenticationTestBase extends TestCase {

protected static final JsonFactory JSON_FACTORY = new JacksonFactory();
protected static final JsonFactory JSON_FACTORY = new GsonFactory();
protected static final String ACCESS_TOKEN = "abc";
protected static final String NEW_ACCESS_TOKEN = "def";
protected static final GenericUrl TOKEN_SERVER_URL = new GenericUrl("http://example.com/token");
Expand Down
Expand Up @@ -16,7 +16,7 @@

import com.google.api.client.auth.oauth2.AuthorizationCodeFlow.CredentialCreatedListener;
import com.google.api.client.http.BasicAuthentication;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.Joiner;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void testCredentialCreatedListener() throws IOException {
new AuthorizationCodeFlow.Builder(
BearerToken.queryParameterAccessMethod(),
new AccessTokenTransport(),
new JacksonFactory(),
new GsonFactory(),
TOKEN_SERVER_URL,
new BasicAuthentication(CLIENT_ID, CLIENT_SECRET),
CLIENT_ID,
Expand All @@ -84,7 +84,7 @@ public void testRefreshListeners() throws IOException {
new AuthorizationCodeFlow.Builder(
BearerToken.queryParameterAccessMethod(),
new AccessTokenTransport(),
new JacksonFactory(),
new GsonFactory(),
TOKEN_SERVER_URL,
new BasicAuthentication(CLIENT_ID, CLIENT_SECRET),
CLIENT_ID,
Expand Down Expand Up @@ -118,7 +118,7 @@ public void subsetTestNewAuthorizationUrl(Collection<String> scopes) {
new AuthorizationCodeFlow.Builder(
BearerToken.queryParameterAccessMethod(),
new AccessTokenTransport(),
new JacksonFactory(),
new GsonFactory(),
TOKEN_SERVER_URL,
new BasicAuthentication(CLIENT_ID, CLIENT_SECRET),
CLIENT_ID,
Expand All @@ -139,7 +139,7 @@ public void testPKCE() {
new AuthorizationCodeFlow.Builder(
BearerToken.queryParameterAccessMethod(),
new AccessTokenTransport(),
new JacksonFactory(),
new GsonFactory(),
TOKEN_SERVER_URL,
new BasicAuthentication(CLIENT_ID, CLIENT_SECRET),
CLIENT_ID,
Expand Down
Expand Up @@ -20,7 +20,7 @@
import com.google.api.client.http.LowLevelHttpRequest;
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.Json;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
Expand All @@ -35,7 +35,7 @@
public class CustomTokenRequestTest extends TestCase {

private static final MockHttpTransport TRANSPORT = new MockHttpTransport();
private static final JacksonFactory JSON_FACTORY = new JacksonFactory();
private static final GsonFactory JSON_FACTORY = new GsonFactory();
private static final GenericUrl AUTHORIZATION_SERVER_URL =
new GenericUrl("https://server.example.com/authorize");
private static final String JWT_ENCODED_CONTENT =
Expand Down
Expand Up @@ -15,7 +15,7 @@
package com.google.api.client.auth.oauth2;

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.Key;
import junit.framework.TestCase;

Expand Down Expand Up @@ -48,7 +48,7 @@ public StringExpiresTokenResponse setExpiresInSeconds(Long expiresInSeconds) {
}

public void testStringExpires() throws Exception {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();
TokenResponse response = jsonFactory.fromString(JSON, StringExpiresTokenResponse.class);
assertEquals("2YotnFZFEjr1zCsicMWpAA", response.getAccessToken());
assertEquals("example", response.getTokenType());
Expand Down
Expand Up @@ -15,7 +15,7 @@
package com.google.api.client.auth.oauth2;

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import junit.framework.TestCase;

/**
Expand All @@ -31,7 +31,7 @@ public class TokenErrorResponseTest extends TestCase {
+ "\"error_description\":\"error description\"}";

public void test() throws Exception {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();
TokenErrorResponse response = jsonFactory.fromString(JSON, TokenErrorResponse.class);
assertEquals("invalid_request", response.getError());
assertEquals("http://www.example.com/error", response.getErrorUri());
Expand Down
Expand Up @@ -15,7 +15,7 @@
package com.google.api.client.auth.oauth2;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import junit.framework.TestCase;

Expand All @@ -27,7 +27,7 @@
public class TokenRequestTest extends TestCase {

static final MockHttpTransport TRANSPORT = new MockHttpTransport();
static final JacksonFactory JSON_FACTORY = new JacksonFactory();
static final GsonFactory JSON_FACTORY = new GsonFactory();
static final GenericUrl AUTHORIZATION_SERVER_URL =
new GenericUrl("https://server.example.com/authorize");

Expand Down
Expand Up @@ -15,7 +15,7 @@
package com.google.api.client.auth.oauth2;

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import junit.framework.TestCase;

/**
Expand All @@ -32,7 +32,7 @@ public class TokenResponseTest extends TestCase {
+ "\"example_parameter\":\"example_value\"}";

public void test() throws Exception {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();
TokenResponse response = jsonFactory.fromString(JSON, TokenResponse.class);
assertEquals("2YotnFZFEjr1zCsicMWpAA", response.getAccessToken());
assertEquals("example", response.getTokenType());
Expand Down
46 changes: 26 additions & 20 deletions samples/dailymotion-cmdline-sample/.project
@@ -1,23 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dailymotion-cmdline-sample</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<name>dailymotion-cmdline-sample</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
Expand Up @@ -28,7 +28,7 @@
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import java.io.File;
Expand Down Expand Up @@ -60,7 +60,7 @@ public class DailyMotionSample {
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

/** Global instance of the JSON factory. */
static final JsonFactory JSON_FACTORY = new JacksonFactory();
static final JsonFactory JSON_FACTORY = new GsonFactory();

private static final String TOKEN_SERVER_URL = "https://api.dailymotion.com/oauth/token";
private static final String AUTHORIZATION_SERVER_URL =
Expand Down
Expand Up @@ -24,7 +24,7 @@
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.MemoryDataStoreFactory;
import java.io.IOException;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class PKCESample {
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

/** Global instance of the JSON factory. */
static final JsonFactory JSON_FACTORY = new JacksonFactory();
static final JsonFactory JSON_FACTORY = new GsonFactory();

private static final String TOKEN_SERVER_URL =
"http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token";
Expand Down