Skip to content

Commit c7d496d

Browse files
committed
Upgrade to HttpCore 4.4.15, Jetty Reactive HttpClient 3.0.5, Google IAM Credential 2.2.0, Google Auth OAuth2 1.7.0, BouncyCastle 1.70
Closes gh-704
1 parent b70a650 commit c7d496d

File tree

5 files changed

+81
-28
lines changed

5 files changed

+81
-28
lines changed

spring-vault-core/src/main/java/org/springframework/vault/authentication/GcpIamAuthentication.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
import com.google.api.client.http.HttpTransport;
2727
import com.google.api.client.http.javanet.NetHttpTransport;
2828
import com.google.api.client.json.JsonFactory;
29-
import com.google.api.client.json.jackson2.JacksonFactory;
3029
import com.google.api.services.iam.v1.Iam;
3130
import com.google.api.services.iam.v1.Iam.Builder;
3231
import com.google.api.services.iam.v1.Iam.Projects.ServiceAccounts.SignJwt;
3332
import com.google.api.services.iam.v1.model.SignJwtRequest;
3433
import com.google.api.services.iam.v1.model.SignJwtResponse;
3534
import com.google.auth.oauth2.GoogleCredentials;
3635

36+
import org.springframework.beans.BeanUtils;
3737
import org.springframework.util.Assert;
38+
import org.springframework.util.ClassUtils;
3839
import org.springframework.vault.VaultException;
3940
import org.springframework.vault.support.VaultToken;
4041
import org.springframework.web.client.RestOperations;
@@ -70,8 +71,6 @@
7071
@Deprecated
7172
public class GcpIamAuthentication extends GcpJwtAuthenticationSupport implements ClientAuthentication {
7273

73-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
74-
7574
private static final String SCOPE = "https://www.googleapis.com/auth/iam";
7675

7776
private final GcpIamAuthenticationOptions options;
@@ -85,7 +84,7 @@ public class GcpIamAuthentication extends GcpJwtAuthenticationSupport implements
8584
* {@link GcpIamAuthenticationOptions} and {@link RestOperations}. This constructor
8685
* initializes {@link GoogleApacheHttpTransport} for Google API usage.
8786
* @param options must not be {@literal null}.
88-
* @param restOperations HTTP client for for Vault login, must not be {@literal null}.
87+
* @param restOperations HTTP client for Vault login, must not be {@literal null}.
8988
*/
9089
public GcpIamAuthentication(GcpIamAuthenticationOptions options, RestOperations restOperations) {
9190
this(options, restOperations, new NetHttpTransport());
@@ -96,7 +95,7 @@ public GcpIamAuthentication(GcpIamAuthenticationOptions options, RestOperations
9695
* {@link GcpIamAuthenticationOptions}, {@link RestOperations} and
9796
* {@link HttpTransport}.
9897
* @param options must not be {@literal null}.
99-
* @param restOperations HTTP client for for Vault login, must not be {@literal null}.
98+
* @param restOperations HTTP client for Vault login, must not be {@literal null}.
10099
* @param httpTransport HTTP client for Google API use, must not be {@literal null}.
101100
*/
102101
public GcpIamAuthentication(GcpIamAuthenticationOptions options, RestOperations restOperations,
@@ -127,12 +126,12 @@ protected String signJwt() {
127126
String serviceAccount = getServiceAccountId();
128127
Map<String, Object> jwtPayload = getJwtPayload(this.options, serviceAccount);
129128

130-
Iam iam = new Builder(this.httpTransport, JSON_FACTORY, this.credential)
129+
Iam iam = new Builder(this.httpTransport, GoogleJsonUtil.JSON_FACTORY, this.credential)
131130
.setApplicationName("Spring Vault/" + getClass().getName()).build();
132131

133132
try {
134133

135-
String payload = JSON_FACTORY.toString(jwtPayload);
134+
String payload = GoogleJsonUtil.JSON_FACTORY.toString(jwtPayload);
136135
SignJwtRequest request = new SignJwtRequest();
137136
request.setPayload(payload);
138137

spring-vault-core/src/main/java/org/springframework/vault/authentication/GcpIamCredentialsAuthentication.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@
2121
import java.util.LinkedHashMap;
2222
import java.util.Map;
2323

24-
import org.springframework.util.Assert;
25-
import org.springframework.vault.VaultException;
26-
import org.springframework.vault.support.VaultToken;
27-
import org.springframework.web.client.RestOperations;
28-
2924
import com.google.api.client.http.HttpTransport;
30-
import com.google.api.client.json.JsonFactory;
31-
import com.google.api.client.json.jackson2.JacksonFactory;
3225
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
3326
import com.google.api.gax.rpc.TransportChannelProvider;
3427
import com.google.auth.oauth2.GoogleCredentials;
@@ -38,6 +31,11 @@
3831
import com.google.cloud.iam.credentials.v1.SignJwtResponse;
3932
import com.google.cloud.iam.credentials.v1.stub.IamCredentialsStubSettings;
4033

34+
import org.springframework.util.Assert;
35+
import org.springframework.vault.VaultException;
36+
import org.springframework.vault.support.VaultToken;
37+
import org.springframework.web.client.RestOperations;
38+
4139
/**
4240
* Google Cloud IAM credentials login implementation using GCP IAM service accounts to
4341
* legitimate its authenticity via JSON Web Token using the IAM Credentials
@@ -66,8 +64,6 @@
6664
*/
6765
public class GcpIamCredentialsAuthentication extends GcpJwtAuthenticationSupport implements ClientAuthentication {
6866

69-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
70-
7167
private final GcpIamCredentialsAuthenticationOptions options;
7268

7369
private final TransportChannelProvider transportChannelProvider;
@@ -80,7 +76,7 @@ public class GcpIamCredentialsAuthentication extends GcpJwtAuthenticationSupport
8076
* constructor initializes {@link InstantiatingGrpcChannelProvider} for Google API
8177
* usage.
8278
* @param options must not be {@literal null}.
83-
* @param restOperations HTTP client for for Vault login, must not be {@literal null}.
79+
* @param restOperations HTTP client for Vault login, must not be {@literal null}.
8480
*/
8581
public GcpIamCredentialsAuthentication(GcpIamCredentialsAuthenticationOptions options,
8682
RestOperations restOperations) {
@@ -92,7 +88,7 @@ public GcpIamCredentialsAuthentication(GcpIamCredentialsAuthenticationOptions op
9288
* {@link GcpIamCredentialsAuthenticationOptions}, {@link RestOperations} and
9389
* {@link TransportChannelProvider}.
9490
* @param options must not be {@literal null}.
95-
* @param restOperations HTTP client for for Vault login, must not be {@literal null}.
91+
* @param restOperations HTTP client for Vault login, must not be {@literal null}.
9692
* @param transportChannelProvider Provider for transport channel Google API use, must
9793
* not be {@literal null}.
9894
*/
@@ -128,7 +124,7 @@ protected String signJwt() {
128124
.setCredentialsProvider(() -> this.credentials)
129125
.setTransportChannelProvider(this.transportChannelProvider).build();
130126
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create(credentialsSettings)) {
131-
String payload = JSON_FACTORY.toString(jwtPayload);
127+
String payload = GoogleJsonUtil.JSON_FACTORY.toString(jwtPayload);
132128
ServiceAccountName serviceAccountName = ServiceAccountName.of("-", serviceAccount);
133129
SignJwtResponse response = iamCredentialsClient.signJwt(serviceAccountName, Collections.emptyList(),
134130
payload);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.vault.authentication;
17+
18+
import com.google.api.client.json.JsonFactory;
19+
20+
import org.springframework.beans.BeanUtils;
21+
import org.springframework.util.ClassUtils;
22+
23+
/**
24+
* Utility to provide JSON-functionality for Google integrations.
25+
*
26+
* @author Mark Paluch
27+
* @since 2.4
28+
*/
29+
class GoogleJsonUtil {
30+
31+
static final JsonFactory JSON_FACTORY;
32+
33+
static final String JACKSON = "com.google.api.client.json.jackson2.JacksonFactory";
34+
35+
static final String GSON = "com.google.api.client.json.gson.GsonFactory";
36+
37+
static {
38+
39+
try {
40+
41+
if (ClassUtils.isPresent(JACKSON, null)) {
42+
JSON_FACTORY = instantiate(JACKSON);
43+
}
44+
else {
45+
JSON_FACTORY = instantiate(GSON);
46+
}
47+
}
48+
catch (ClassNotFoundException e) {
49+
throw new IllegalStateException(
50+
String.format("No com.google.api.client.json.JsonFactory implementation available. Make sure to include either %s or %s on your classpath.", JACKSON, GSON),
51+
e);
52+
}
53+
}
54+
55+
private static JsonFactory instantiate(String name) throws ClassNotFoundException {
56+
return (JsonFactory) BeanUtils.instantiateClass(ClassUtils.forName(name, null));
57+
}
58+
59+
}

spring-vault-core/src/test/java/org/springframework/vault/authentication/GcpIamAuthenticationUnitTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
2727
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder;
2828
import com.google.api.client.googleapis.testing.auth.oauth2.MockGoogleCredential;
29-
import com.google.api.client.json.jackson2.JacksonFactory;
29+
import com.google.api.client.json.gson.GsonFactory;
3030
import com.google.api.client.testing.http.MockHttpTransport;
3131
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
32-
import com.google.api.client.testing.json.MockJsonFactory;
3332
import org.junit.jupiter.api.BeforeEach;
3433
import org.junit.jupiter.api.Test;
3534

@@ -81,7 +80,7 @@ void shouldLogin() throws NoSuchAlgorithmException {
8180

8281
GoogleCredential credential = new MockGoogleCredential.Builder().setServiceAccountId("hello@world")
8382
.setServiceAccountProjectId("foobar").setServiceAccountPrivateKey(key.getPrivate())
84-
.setServiceAccountPrivateKeyId("key-id").setJsonFactory(new JacksonFactory())
83+
.setServiceAccountPrivateKeyId("key-id").setJsonFactory(new GsonFactory())
8584
.setTransport(new MockHttpTransport.Builder().setLowLevelHttpResponse(createMockHttpResponse()).build())
8685
.build();
8786
credential.setAccessToken("foobar");

spring-vault-dependencies/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@
5858

5959
<properties>
6060
<httpclient.version>4.5.13</httpclient.version>
61-
<httpcore.version>4.4.14</httpcore.version>
62-
<jetty-reactive-httpclient.version>3.0.4</jetty-reactive-httpclient.version>
61+
<httpcore.version>4.4.15</httpcore.version>
62+
<jetty-reactive-httpclient.version>3.0.5</jetty-reactive-httpclient.version>
6363
<netty.version>4.1.77.Final</netty.version>
6464
<okhttp3.version>3.14.9</okhttp3.version>
6565
<jackson-databind.version>2.13.3</jackson-databind.version>
6666
<aws-java-sdk.version>2.17.195</aws-java-sdk.version>
67-
<google-api-services-iam.version>v1-rev20210226-1.31.0</google-api-services-iam.version>
68-
<google-cloud-iamcredentials.version>1.2.2</google-cloud-iamcredentials.version>
69-
<google-auth-library-oauth2-http.version>0.22.2</google-auth-library-oauth2-http.version>
70-
<bcpkix-jdk15on.version>1.68</bcpkix-jdk15on.version>
67+
<google-api-services-iam.version>v1-rev20220511-1.32.1</google-api-services-iam.version>
68+
<google-cloud-iamcredentials.version>2.2.0</google-cloud-iamcredentials.version>
69+
<google-auth-library-oauth2-http.version>1.7.0</google-auth-library-oauth2-http.version>
70+
<bcpkix-jdk15on.version>1.70</bcpkix-jdk15on.version>
7171
</properties>
7272

7373
<dependencyManagement>

0 commit comments

Comments
 (0)