Skip to content

Commit e3a2e9c

Browse files
BigTailWolflsirac
andauthored
fix: Issue #1347: ExternalAccountCredentials serialization is broken (#1358)
* fix: Issue #1347: ExternalAccountCredentials serialization is broken * fix test * fix lint * Update oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java Co-authored-by: Leo <39062083+lsirac@users.noreply.github.com> * address the removal of redaundant public * move the getter to test class --------- Co-authored-by: Leo <39062083+lsirac@users.noreply.github.com>
1 parent 6ec1116 commit e3a2e9c

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;
@@ -555,6 +556,13 @@ public CredentialSource getCredentialSource() {
555556
return credentialSource;
556557
}
557558

559+
@SuppressWarnings("unused")
560+
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
561+
// Properly deserialize the transient transportFactory.
562+
input.defaultReadObject();
563+
transportFactory = newInstance(transportFactoryClassName);
564+
}
565+
558566
@Nullable
559567
public String getServiceAccountImpersonationUrl() {
560568
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
@@ -1109,6 +1109,9 @@ public void serialize() throws IOException, ClassNotFoundException {
11091109
testCredentials.getServiceAccountImpersonationOptions().getLifetime(),
11101110
deserializedCredentials.getServiceAccountImpersonationOptions().getLifetime());
11111111
assertSame(deserializedCredentials.clock, Clock.SYSTEM);
1112+
assertEquals(
1113+
MockExternalAccountCredentialsTransportFactory.class,
1114+
deserializedCredentials.toBuilder().getHttpTransportFactory().getClass());
11121115
}
11131116

11141117
@Test
@@ -1299,17 +1302,30 @@ protected TestCredentialSource(Map<String, Object> credentialSourceMap) {
12991302
}
13001303
}
13011304

1305+
@Override
1306+
public Builder toBuilder() {
1307+
return new Builder(this);
1308+
}
1309+
13021310
public static Builder newBuilder() {
13031311
return new Builder();
13041312
}
13051313

13061314
static class Builder extends ExternalAccountCredentials.Builder {
13071315
Builder() {}
13081316

1317+
Builder(TestExternalAccountCredentials credentials) {
1318+
super(credentials);
1319+
}
1320+
13091321
@Override
13101322
public TestExternalAccountCredentials build() {
13111323
return new TestExternalAccountCredentials(this);
13121324
}
1325+
1326+
public HttpTransportFactory getHttpTransportFactory() {
1327+
return transportFactory;
1328+
}
13131329
}
13141330

13151331
protected TestExternalAccountCredentials(ExternalAccountCredentials.Builder builder) {

0 commit comments

Comments
 (0)