Switch from GoogleApacheHttpTransport to NetHttpTransport.

GoogleApacheHttpTransport breaks with the current 4.5.x HttpClient dependency so we're switching to NetHttpTransport that uses HttpURLConnection.

Closes gh-463.
This commit is contained in:
Mark Paluch
2019-09-02 09:34:51 +02:00
parent e7ad81a78f
commit 2aa74c7973
2 changed files with 21 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import java.util.Map;
import com.google.api.client.googleapis.apache.GoogleApacheHttpTransport;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
@@ -88,7 +89,7 @@ public class GcpIamAuthentication extends GcpJwtAuthenticationSupport
*/
public GcpIamAuthentication(GcpIamAuthenticationOptions options,
RestOperations restOperations) throws GeneralSecurityException, IOException {
this(options, restOperations, GoogleApacheHttpTransport.newTrustedTransport());
this(options, restOperations, new NetHttpTransport());
}
/**

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.vault.authentication;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.time.Duration;
@@ -100,4 +102,21 @@ class GcpIamAuthenticationUnitTests {
assertThat(loginToken.isRenewable()).isTrue();
assertThat(loginToken.getLeaseDuration()).isEqualTo(Duration.ofSeconds(10));
}
@Test
void shouldCreateNewGcpIamObjectInstance()
throws GeneralSecurityException, IOException {
PrivateKey privateKeyMock = mock(PrivateKey.class);
GoogleCredential credential = new Builder().setServiceAccountId("hello@world")
.setServiceAccountProjectId("foobar")
.setServiceAccountPrivateKey(privateKeyMock)
.setServiceAccountPrivateKeyId("key-id").build();
credential.setAccessToken("foobar");
GcpIamAuthenticationOptions options = GcpIamAuthenticationOptions.builder()
.role("dev-role").credential(credential).build();
new GcpIamAuthentication(options, restTemplate);
}
}