Skip to content

Commit b1096fe

Browse files
authored
Revert "Revert "fix: Issue #1347: ExternalAccountCredentials serialization is…" (#1365)
This reverts commit 5a2d943.
1 parent bd898c6 commit b1096fe

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.google.errorprone.annotations.CanIgnoreReturnValue;
4343
import java.io.IOException;
4444
import java.io.InputStream;
45+
import java.io.ObjectInputStream;
4546
import java.math.BigDecimal;
4647
import java.net.URI;
4748
import java.nio.charset.StandardCharsets;
@@ -540,6 +541,13 @@ public CredentialSource getCredentialSource() {
540541
return credentialSource;
541542
}
542543

544+
@SuppressWarnings("unused")
545+
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
546+
// Properly deserialize the transient transportFactory.
547+
input.defaultReadObject();
548+
transportFactory = newInstance(transportFactoryClassName);
549+
}
550+
543551
@Nullable
544552
public String getServiceAccountImpersonationUrl() {
545553
return serviceAccountImpersonationUrl;

oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,9 @@ public void serialize() throws IOException, ClassNotFoundException {
11171117
testCredentials.getServiceAccountImpersonationOptions().getLifetime(),
11181118
deserializedCredentials.getServiceAccountImpersonationOptions().getLifetime());
11191119
assertSame(deserializedCredentials.clock, Clock.SYSTEM);
1120+
assertEquals(
1121+
MockExternalAccountCredentialsTransportFactory.class,
1122+
deserializedCredentials.toBuilder().getHttpTransportFactory().getClass());
11201123
}
11211124

11221125
@Test
@@ -1307,17 +1310,30 @@ protected TestCredentialSource(Map<String, Object> credentialSourceMap) {
13071310
}
13081311
}
13091312

1313+
@Override
1314+
public Builder toBuilder() {
1315+
return new Builder(this);
1316+
}
1317+
13101318
public static Builder newBuilder() {
13111319
return new Builder();
13121320
}
13131321

13141322
static class Builder extends ExternalAccountCredentials.Builder {
13151323
Builder() {}
13161324

1325+
Builder(TestExternalAccountCredentials credentials) {
1326+
super(credentials);
1327+
}
1328+
13171329
@Override
13181330
public TestExternalAccountCredentials build() {
13191331
return new TestExternalAccountCredentials(this);
13201332
}
1333+
1334+
public HttpTransportFactory getHttpTransportFactory() {
1335+
return transportFactory;
1336+
}
13211337
}
13221338

13231339
protected TestExternalAccountCredentials(ExternalAccountCredentials.Builder builder) {

0 commit comments

Comments
 (0)