Skip to content

Commit 63f7f4a

Browse files
committed
Polishing.
Update documentation, extract base class for GCP IAM authentication options. Closes gh-600. Original pull request: gh-619.
1 parent 53f14ab commit 63f7f4a

File tree

12 files changed

+184
-188
lines changed

12 files changed

+184
-188
lines changed

spring-vault-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
<dependency>
198198
<groupId>com.google.cloud</groupId>
199199
<artifactId>google-cloud-iamcredentials</artifactId>
200+
<optional>true</optional>
200201
<exclusions>
201202
<exclusion>
202203
<groupId>com.fasterxml.jackson.core</groupId>
@@ -211,7 +212,6 @@
211212
<groupId>commons-logging</groupId>
212213
</exclusion>
213214
</exclusions>
214-
<optional>true</optional>
215215
</dependency>
216216

217217
<dependency>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import com.google.auth.oauth2.ServiceAccountCredentials;
2222

2323
/**
24-
* Default implementation of {@link GcpCredentialsAccountIdAccessor}. Used by
24+
* Default implementation of {@link GoogleCredentialsAccountIdAccessor}. Used by
2525
* {@link GcpIamCredentialsAuthentication}.
2626
*
2727
* @author Andreas Gebauer
28-
* @since 2.4
28+
* @since 2.3.2
2929
* @see GcpIamCredentialsAuthentication
3030
*/
31-
enum DefaultGcpCredentialsAccessors implements GcpCredentialsAccountIdAccessor {
31+
enum DefaultGoogleCredentialsAccessors implements GoogleCredentialsAccountIdAccessor {
3232

3333
INSTANCE;
3434

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141

4242
/**
4343
* GCP IAM login implementation using GCP IAM service accounts to legitimate its
44-
* authenticity via JSON Web Token.
44+
* authenticity via JSON Web Token using the deprecated IAM
45+
* {@code projects.serviceAccounts.signJwt} method.
4546
* <p/>
4647
* This authentication method uses Googles IAM API to obtain a signed token for a specific
4748
* {@link com.google.api.client.auth.oauth2.Credential}. Project and service account
@@ -64,7 +65,7 @@
6465
* @see <a href=
6566
* "https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signJwt">GCP:
6667
* projects.serviceAccounts.signJwt</a>
67-
* @deprecated Use {@link GcpIamCredentialsAuthentication} instead.
68+
* @deprecated since 2.3.2, use {@link GcpIamCredentialsAuthentication} instead.
6869
*/
6970
@Deprecated
7071
public class GcpIamAuthentication extends GcpJwtAuthenticationSupport implements ClientAuthentication {

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

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,15 @@
3636
* @see GcpIamAuthentication
3737
* @see #builder()
3838
* @since 2.1
39+
* @deprecated since 2.3.2
3940
*/
40-
public class GcpIamAuthenticationOptions {
41+
@Deprecated
42+
public class GcpIamAuthenticationOptions extends GcpIamAuthenticationSupport {
4143

4244
public static final String DEFAULT_GCP_AUTHENTICATION_PATH = "gcp";
4345

44-
/**
45-
* Path of the gcp authentication backend mount.
46-
*/
47-
private final String path;
48-
4946
private final GcpCredentialSupplier credentialSupplier;
5047

51-
/**
52-
* Name of the role against which the login is being attempted. If role is not
53-
* specified, the friendly name (i.e., role name or username) of the IAM principal
54-
* authenticated. If a matching role is not found, login fails.
55-
*/
56-
private final String role;
57-
58-
/**
59-
* JWT validity/expiration.
60-
*/
61-
private final Duration jwtValidity;
62-
63-
/**
64-
* {@link Clock} to calculate JWT expiration.
65-
*/
66-
private final Clock clock;
67-
6848
/**
6949
* Provide the service account id to use as sub/iss claims.
7050
*/
@@ -79,11 +59,9 @@ private GcpIamAuthenticationOptions(String path, GcpCredentialSupplier credentia
7959
Duration jwtValidity, Clock clock, GcpServiceAccountIdAccessor serviceAccountIdSupplier,
8060
GcpProjectIdAccessor projectIdAccessor) {
8161

82-
this.path = path;
62+
super(path, role, jwtValidity, clock);
63+
8364
this.credentialSupplier = credentialSupplier;
84-
this.role = role;
85-
this.jwtValidity = jwtValidity;
86-
this.clock = clock;
8765
this.serviceAccountIdAccessor = serviceAccountIdSupplier;
8866
this.projectIdAccessor = projectIdAccessor;
8967
}
@@ -95,41 +73,13 @@ public static GcpIamAuthenticationOptionsBuilder builder() {
9573
return new GcpIamAuthenticationOptionsBuilder();
9674
}
9775

98-
/**
99-
* @return the path of the gcp authentication backend mount.
100-
*/
101-
public String getPath() {
102-
return this.path;
103-
}
104-
10576
/**
10677
* @return the gcp {@link Credential} supplier.
10778
*/
10879
public GcpCredentialSupplier getCredentialSupplier() {
10980
return this.credentialSupplier;
11081
}
11182

112-
/**
113-
* @return name of the role against which the login is being attempted.
114-
*/
115-
public String getRole() {
116-
return this.role;
117-
}
118-
119-
/**
120-
* @return {@link Duration} of the JWT to generate.
121-
*/
122-
public Duration getJwtValidity() {
123-
return this.jwtValidity;
124-
}
125-
126-
/**
127-
* @return {@link Clock} used to calculate epoch seconds until the JWT expires.
128-
*/
129-
public Clock getClock() {
130-
return this.clock;
131-
}
132-
13383
/**
13484
* @return the service account id to use as sub/iss claims.
13585
* @since 2.1
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2018-2021 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 java.time.Clock;
19+
import java.time.Duration;
20+
21+
/**
22+
* Support class for Google Cloud IAM-based Authentication options.
23+
* <p/>
24+
* Mainly to support implementations within the framework.
25+
*
26+
* @author Mark Paluch
27+
* @since 2.3.2
28+
* @see GcpIamAuthenticationOptions
29+
* @see GcpIamCredentialsAuthenticationOptions
30+
*/
31+
public abstract class GcpIamAuthenticationSupport {
32+
33+
/**
34+
* Path of the gcp authentication backend mount.
35+
*/
36+
private final String path;
37+
38+
/**
39+
* Name of the role against which the login is being attempted. If role is not
40+
* specified, the friendly name (i.e., role name or username) of the IAM principal
41+
* authenticated. If a matching role is not found, login fails.
42+
*/
43+
private final String role;
44+
45+
/**
46+
* JWT validity/expiration.
47+
*/
48+
private final Duration jwtValidity;
49+
50+
/**
51+
* {@link Clock} to calculate JWT expiration.
52+
*/
53+
private final Clock clock;
54+
55+
protected GcpIamAuthenticationSupport(String path, String role, Duration jwtValidity, Clock clock) {
56+
57+
this.path = path;
58+
this.role = role;
59+
this.jwtValidity = jwtValidity;
60+
this.clock = clock;
61+
}
62+
63+
/**
64+
* @return the path of the gcp authentication backend mount.
65+
*/
66+
public String getPath() {
67+
return this.path;
68+
}
69+
70+
/**
71+
* @return name of the role against which the login is being attempted.
72+
*/
73+
public String getRole() {
74+
return this.role;
75+
}
76+
77+
/**
78+
* @return {@link Duration} of the JWT to generate.
79+
*/
80+
public Duration getJwtValidity() {
81+
return this.jwtValidity;
82+
}
83+
84+
/**
85+
* @return {@link Clock} used to calculate epoch seconds until the JWT expires.
86+
*/
87+
public Clock getClock() {
88+
return this.clock;
89+
}
90+
91+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
import com.google.cloud.iam.credentials.v1.stub.IamCredentialsStubSettings;
4040

4141
/**
42-
* GCP IAM credentials login implementation using GCP IAM service accounts to legitimate
43-
* its authenticity via JSON Web Token.
42+
* Google Cloud IAM credentials login implementation using GCP IAM service accounts to
43+
* legitimate its authenticity via JSON Web Token using the IAM Credentials
44+
* {@code projects.serviceAccounts.signJwt} method.
4445
* <p/>
4546
* This authentication method uses Googles IAM Credentials API to obtain a signed token
4647
* for a specific {@link com.google.api.client.auth.oauth2.Credential}. Service account
@@ -50,7 +51,8 @@
5051
* {@link GcpIamCredentialsAuthentication} uses Google Java API that uses synchronous API.
5152
*
5253
* @author Andreas Gebauer
53-
* @since 2.4
54+
* @author Mark Paluch
55+
* @since 2.3.2
5456
* @see GcpIamCredentialsAuthenticationOptions
5557
* @see HttpTransport
5658
* @see GoogleCredentials

0 commit comments

Comments
 (0)