Skip to content

Commit

Permalink
Merge branch 'master' into promote-beta-features
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-merge-on-green[bot] authored Jan 26, 2021
2 parents cd43e09 + 9a11c50 commit 9e7f1ee
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 118 deletions.
3 changes: 3 additions & 0 deletions .kokoro/release/publish_javadoc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ before_action {
}
}
}

# Downloads docfx doclet resource. This will be in ${KOKORO_GFILE_DIR}/<doclet name>
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/docfx"
30 changes: 0 additions & 30 deletions appengine/java/com/google/auth/appengine/AppEngineCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.appengine.api.appidentity.AppIdentityService.GetAccessTokenResult;
import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.base.MoreObjects;
Expand All @@ -46,7 +45,6 @@
import java.util.Collection;
import java.util.Date;
import java.util.Objects;
import java.util.logging.Logger;

/**
* OAuth2 credentials representing the built-in service account for Google App Engine. You should
Expand All @@ -56,7 +54,6 @@
*/
public class AppEngineCredentials extends GoogleCredentials implements ServiceAccountSigner {

private static final Logger logger = Logger.getLogger(AppEngineCredentials.class.getName());
private static final long serialVersionUID = -2627708355455064660L;

private final String appIdentityServiceClassName;
Expand All @@ -65,33 +62,6 @@ public class AppEngineCredentials extends GoogleCredentials implements ServiceAc

private transient AppIdentityService appIdentityService;

/**
* @deprecated AppEngineCredentials should be instantiated via its Builder. See
* https://github.com/googleapis/google-auth-library-java#google-auth-library-appengine
*/
@Deprecated
public static GoogleCredentials getApplicationDefault() throws IOException {
logger.warning(
"You are attempting to "
+ "fetch Application Default Credentials from com.google.auth.appengine.AppEngineCredentials."
+ " This method will not return a com.google.auth.appengine.AppEngineCredentials instance.");
return GoogleCredentials.getApplicationDefault();
}

/**
* @deprecated AppEngineCredentials should be instantiated via its Builder. See
* https://github.com/googleapis/google-auth-library-java#google-auth-library-appengine
*/
@Deprecated
public static GoogleCredentials getApplicationDefault(HttpTransportFactory transportFactory)
throws IOException {
logger.warning(
"You are attempting to fetch "
+ "Application Default Credentials from com.google.auth.appengine.AppEngineCredentials. "
+ "This method does not return a com.google.auth.appengine.AppEngineCredentials instance.");
return GoogleCredentials.getApplicationDefault(transportFactory);
}

private AppEngineCredentials(Collection<String> scopes, AppIdentityService appIdentityService) {
this.scopes = scopes == null ? ImmutableSet.<String>of() : ImmutableList.copyOf(scopes);
this.appIdentityService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.api.client.http.HttpTransport;
import com.google.auth.Credentials;
import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.BaseSerializationTest;
import com.google.auth.oauth2.GoogleCredentials;
Expand All @@ -53,9 +51,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -264,61 +259,4 @@ private static void assertContainsBearerToken(Map<String, List<String>> metadata
}
assertTrue("Bearer token not found", found);
}

@Test
@SuppressWarnings("deprecation")
public void warnsDefaultCredentials() {
Logger logger = Logger.getLogger(AppEngineCredentials.class.getName());
LogHandler handler = new LogHandler();
logger.addHandler(handler);

try {
Credentials unused = AppEngineCredentials.getApplicationDefault();
} catch (IOException ex) {
// ignore - this may just fail for not being in a supported environment
}

LogRecord message = handler.getRecord();
assertTrue(message.getMessage().contains("You are attempting to"));
}

@Test
@SuppressWarnings("deprecation")
public void warnsDefaultCredentialsWithTransport() {
Logger logger = Logger.getLogger(AppEngineCredentials.class.getName());
LogHandler handler = new LogHandler();
logger.addHandler(handler);

try {
Credentials unused =
AppEngineCredentials.getApplicationDefault(
new HttpTransportFactory() {
@Override
public HttpTransport create() {
return null;
}
});
} catch (IOException ex) {
// ignore - this may just fail for not being in a supported environment
}

LogRecord message = handler.getRecord();
assertTrue(message.getMessage().contains("You are attempting to"));
}

private class LogHandler extends Handler {
LogRecord lastRecord;

public void publish(LogRecord record) {
lastRecord = record;
}

public LogRecord getRecord() {
return lastRecord;
}

public void close() {}

public void flush() {}
}
}
4 changes: 0 additions & 4 deletions appengine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
Expand Down
27 changes: 18 additions & 9 deletions oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.auth.http.AuthHttpConstants;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import java.io.IOException;
Expand Down Expand Up @@ -131,7 +130,10 @@ public void getRequestMetadata(
super.getRequestMetadata(uri, executor, callback);
return;
}
metadata = Preconditions.checkNotNull(requestMetadata, "cached requestMetadata");
if (requestMetadata == null) {
throw new NullPointerException("cached requestMetadata");
}
metadata = requestMetadata;
}
callback.onSuccess(metadata);
}
Expand All @@ -146,7 +148,10 @@ public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException
if (shouldRefresh()) {
refresh();
}
return Preconditions.checkNotNull(requestMetadata, "requestMetadata");
if (requestMetadata == null) {
throw new NullPointerException("requestMetadata");
}
return requestMetadata;
}
}

Expand All @@ -156,9 +161,11 @@ public void refresh() throws IOException {
synchronized (lock) {
requestMetadata = null;
temporaryAccess = null;
useAccessToken(
Preconditions.checkNotNull(refreshAccessToken(), "new access token"),
getAdditionalHeaders());
AccessToken accessToken = refreshAccessToken();
if (accessToken == null) {
throw new NullPointerException("new access token");
}
useAccessToken(accessToken, getAdditionalHeaders());
if (changeListeners != null) {
for (CredentialsChangedListener listener : changeListeners) {
listener.onChanged(this);
Expand Down Expand Up @@ -214,8 +221,10 @@ private boolean shouldRefresh() {
* <p>Throws IllegalStateException if not overridden since direct use of OAuth2Credentials is only
* for temporary or non-refreshing access tokens.
*
* @return Refreshed access token.
* @throws IOException from derived implementations
* @return never
* @throws IllegalStateException always. OAuth2Credentials does not support refreshing the access
* token. An instance with a new access token or a derived type that supports refreshing
* should be used instead.
*/
public AccessToken refreshAccessToken() throws IOException {
throw new IllegalStateException(
Expand All @@ -230,7 +239,7 @@ public AccessToken refreshAccessToken() throws IOException {
* <p>This is called when token content changes, such as when the access token is refreshed. This
* is typically used by code caching the access token.
*
* @param listener The listener to be added.
* @param listener the listener to be added
*/
public final void addChangeListener(CredentialsChangedListener listener) {
synchronized (lock) {
Expand Down
Loading

0 comments on commit 9e7f1ee

Please sign in to comment.