Skip to content

Commit c007f3c

Browse files
committed
feat: use self-signed JWTs in Spanner MutableCredentials
1 parent ff45dd2 commit c007f3c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MutableCredentials.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public MutableCredentials(
5858
throw new IllegalArgumentException("Scopes must not be empty");
5959
}
6060
this.scopes = new java.util.HashSet<>(scopes);
61-
delegate = (ServiceAccountCredentials) credentials.createScoped(this.scopes);
61+
delegate =
62+
((ServiceAccountCredentials) credentials.createScoped(this.scopes))
63+
.createWithUseJwtAccessWithScope(true);
6264
}
6365

6466
/**
@@ -74,7 +76,9 @@ public MutableCredentials(
7476
*/
7577
public void updateCredentials(@Nonnull ServiceAccountCredentials credentials) {
7678
Objects.requireNonNull(credentials, "credentials must not be null");
77-
delegate = (ServiceAccountCredentials) credentials.createScoped(scopes);
79+
delegate =
80+
((ServiceAccountCredentials) credentials.createScoped(scopes))
81+
.createWithUseJwtAccessWithScope(true);
7882
}
7983

8084
@Override

java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public void testCreateMutableCredentials() throws IOException {
8686
public void testCreateMutableCredentialsWithDefaultScopes() throws IOException {
8787
Set<String> defaultScopes = SpannerOptions.SCOPES;
8888
when(initialCredentials.createScoped(defaultScopes)).thenReturn(initialScopedCredentials);
89+
when(initialScopedCredentials.createWithUseJwtAccessWithScope(true))
90+
.thenReturn(initialScopedCredentials);
8991
when(initialScopedCredentials.getAuthenticationType()).thenReturn(initialAuthType);
9092
when(initialScopedCredentials.getRequestMetadata(any(URI.class))).thenReturn(initialMetadata);
9193
when(initialScopedCredentials.getUniverseDomain()).thenReturn(initialUniverseDomain);
@@ -172,6 +174,8 @@ private void validateInitialDelegatedCredentialsAreSet(
172174

173175
private void setupInitialCredentials() throws IOException {
174176
when(initialCredentials.createScoped(scopes)).thenReturn(initialScopedCredentials);
177+
when(initialScopedCredentials.createWithUseJwtAccessWithScope(true))
178+
.thenReturn(initialScopedCredentials);
175179
when(initialCredentials.createScoped(Collections.emptyList()))
176180
.thenReturn(initialScopedCredentials);
177181
when(initialScopedCredentials.getAuthenticationType()).thenReturn(initialAuthType);
@@ -185,6 +189,8 @@ private void setupInitialCredentials() throws IOException {
185189

186190
private void setupUpdatedCredentials() throws IOException {
187191
when(updatedCredentials.createScoped(scopes)).thenReturn(updatedScopedCredentials);
192+
when(updatedScopedCredentials.createWithUseJwtAccessWithScope(true))
193+
.thenReturn(updatedScopedCredentials);
188194
when(updatedScopedCredentials.getAuthenticationType()).thenReturn(updatedAuthType);
189195
when(updatedScopedCredentials.getRequestMetadata(any(URI.class))).thenReturn(updatedMetadata);
190196
when(updatedScopedCredentials.getUniverseDomain()).thenReturn(updatedUniverseDomain);

0 commit comments

Comments
 (0)