Skip to content

Commit e6b6e18

Browse files
committed
S2A -> SecureSessionAgent.
1 parent a66aecf commit e6b6e18

File tree

5 files changed

+60
-54
lines changed

5 files changed

+60
-54
lines changed

oauth2_http/java/com/google/auth/oauth2/S2A.java renamed to oauth2_http/java/com/google/auth/oauth2/SecureSessionAgent.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* <p>This is an experimental utility.
5959
*/
6060
@ThreadSafe
61-
public class S2A {
61+
public class SecureSessionAgent {
6262
static final String S2A_PLAINTEXT_ADDRESS_JSON_KEY = "plaintext_address";
6363
static final String S2A_MTLS_ADDRESS_JSON_KEY = "mtls_address";
6464
static final String S2A_CONFIG_ENDPOINT_POSTFIX =
@@ -72,17 +72,17 @@ public class S2A {
7272
private static final String MDS_MTLS_ENDPOINT =
7373
ComputeEngineCredentials.getMetadataServerUrl() + S2A_CONFIG_ENDPOINT_POSTFIX;
7474

75-
private S2AConfig config;
75+
private SecureSessionAgentConfig config;
7676

7777
private transient HttpTransportFactory transportFactory;
7878

79-
S2A(S2A.Builder builder) {
79+
SecureSessionAgent(SecureSessionAgent.Builder builder) {
8080
this.transportFactory = builder.getHttpTransportFactory();
81-
this.config = getS2AConfigFromMDS();
81+
this.config = getSecureSessionAgentConfigFromMDS();
8282
}
8383

84-
/** @return the cached S2AConfig. */
85-
public S2AConfig getConfigFromMDS() {
84+
/** @return the cached SecureSessionAgentConfig. */
85+
public SecureSessionAgentConfig getConfigFromMDS() {
8686
return config;
8787
}
8888

@@ -105,17 +105,18 @@ public HttpTransportFactory getHttpTransportFactory() {
105105
return this.transportFactory;
106106
}
107107

108-
public S2A build() {
109-
return new S2A(this);
108+
public SecureSessionAgent build() {
109+
return new SecureSessionAgent(this);
110110
}
111111
}
112112

113113
/**
114-
* Queries the MDS mTLS Autoconfiguration endpoint and returns the {@link S2AConfig}.
114+
* Queries the MDS mTLS Autoconfiguration endpoint and returns the {@link
115+
* SecureSessionAgentConfig}.
115116
*
116-
* <p>Returns {@link S2AConfig}. If S2A is not running, or if any error occurs when making the
117-
* request to MDS / processing the response, {@link S2AConfig} will be populated with empty
118-
* addresses.
117+
* <p>Returns {@link SecureSessionAgentConfig}. If S2A is not running, or if any error occurs when
118+
* making the request to MDS / processing the response, {@link SecureSessionAgentConfig} will be
119+
* populated with empty addresses.
119120
*
120121
* <p>Users are expected to try to fetch the mTLS-S2A address first (via {@link
121122
* getMtlsS2AAddress}). If it is empty or they have some problem loading the mTLS-MDS credentials,
@@ -124,9 +125,9 @@ public S2A build() {
124125
* when talking to the MDS / processing the response or that S2A is not running in the
125126
* environment; in either case this indicates S2A shouldn't be used.
126127
*
127-
* @return the {@link S2AConfig}.
128+
* @return the {@link SecureSessionAgentConfig}.
128129
*/
129-
private S2AConfig getS2AConfigFromMDS() {
130+
private SecureSessionAgentConfig getSecureSessionAgentConfigFromMDS() {
130131
if (transportFactory == null) {
131132
transportFactory =
132133
Iterables.getFirst(
@@ -139,9 +140,9 @@ private S2AConfig getS2AConfigFromMDS() {
139140
request = transportFactory.create().createRequestFactory().buildGetRequest(genericUrl);
140141
} catch (IOException ignore) {
141142
/*
142-
* Return empty addresses in {@link S2AConfig} if error building the GET request.
143+
* Return empty addresses in {@link SecureSessionAgentConfig} if error building the GET request.
143144
*/
144-
return S2AConfig.createBuilder().build();
145+
return SecureSessionAgentConfig.createBuilder().build();
145146
}
146147

147148
request.setParser(new JsonObjectParser(OAuth2Utils.JSON_FACTORY));
@@ -168,14 +169,14 @@ private S2AConfig getS2AConfigFromMDS() {
168169
HttpResponse response = request.execute();
169170
InputStream content = response.getContent();
170171
if (content == null) {
171-
return S2AConfig.createBuilder().build();
172+
return SecureSessionAgentConfig.createBuilder().build();
172173
}
173174
responseData = response.parseAs(GenericData.class);
174175
} catch (IOException ignore) {
175176
/*
176-
* Return empty addresses in {@link S2AConfig} once all retries have been exhausted.
177+
* Return empty addresses in {@link SecureSessionAgentConfig} once all retries have been exhausted.
177178
*/
178-
return S2AConfig.createBuilder().build();
179+
return SecureSessionAgentConfig.createBuilder().build();
179180
}
180181

181182
String plaintextS2AAddress = "";
@@ -185,19 +186,19 @@ private S2AConfig getS2AConfigFromMDS() {
185186
OAuth2Utils.validateString(responseData, S2A_PLAINTEXT_ADDRESS_JSON_KEY, PARSE_ERROR_S2A);
186187
} catch (IOException ignore) {
187188
/*
188-
* Do not throw error because of parsing error, just leave the address as empty in {@link S2AConfig}.
189+
* Do not throw error because of parsing error, just leave the address as empty in {@link SecureSessionAgentConfig}.
189190
*/
190191
}
191192
try {
192193
mtlsS2AAddress =
193194
OAuth2Utils.validateString(responseData, S2A_MTLS_ADDRESS_JSON_KEY, PARSE_ERROR_S2A);
194195
} catch (IOException ignore) {
195196
/*
196-
* Do not throw error because of parsing error, just leave the address as empty in {@link S2AConfig}.
197+
* Do not throw error because of parsing error, just leave the address as empty in {@link SecureSessionAgentConfig}.
197198
*/
198199
}
199200

200-
return S2AConfig.createBuilder()
201+
return SecureSessionAgentConfig.createBuilder()
201202
.setPlaintextAddress(plaintextS2AAddress)
202203
.setMtlsAddress(mtlsS2AAddress)
203204
.build();

oauth2_http/java/com/google/auth/oauth2/S2AConfig.java renamed to oauth2_http/java/com/google/auth/oauth2/SecureSessionAgentConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3434

3535
/** Holds an mTLS configuration (consists of address of S2A) retrieved from the Metadata Server. */
36-
public class S2AConfig {
36+
public class SecureSessionAgentConfig {
3737
// plaintextAddress is the plaintext address to reach the S2A.
3838
private final String plaintextAddress;
3939

@@ -86,12 +86,12 @@ public Builder setMtlsAddress(String mtlsAddress) {
8686
return this;
8787
}
8888

89-
public S2AConfig build() {
90-
return new S2AConfig(plaintextAddress, mtlsAddress);
89+
public SecureSessionAgentConfig build() {
90+
return new SecureSessionAgentConfig(plaintextAddress, mtlsAddress);
9191
}
9292
}
9393

94-
private S2AConfig(String plaintextAddress, String mtlsAddress) {
94+
private SecureSessionAgentConfig(String plaintextAddress, String mtlsAddress) {
9595
this.plaintextAddress = plaintextAddress;
9696
this.mtlsAddress = mtlsAddress;
9797
}

oauth2_http/javatests/com/google/auth/oauth2/MockMetadataServerTransport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ private MockLowLevelHttpRequest getMockRequestForMtlsConfig(String url) {
291291
@Override
292292
public LowLevelHttpResponse execute() throws IOException {
293293

294-
String metadataRequestHeader = getFirstHeaderValue(S2A.METADATA_FLAVOR);
295-
if (!S2A.GOOGLE.equals(metadataRequestHeader)) {
294+
String metadataRequestHeader = getFirstHeaderValue(SecureSessionAgent.METADATA_FLAVOR);
295+
if (!SecureSessionAgent.GOOGLE.equals(metadataRequestHeader)) {
296296
throw new IOException("Metadata request header not found");
297297
}
298298

@@ -337,6 +337,6 @@ protected boolean isIdentityDocumentUrl(String url) {
337337
protected boolean isMtlsConfigRequestUrl(String url) {
338338
return url.equals(
339339
String.format(
340-
ComputeEngineCredentials.getMetadataServerUrl() + S2A.S2A_CONFIG_ENDPOINT_POSTFIX));
340+
ComputeEngineCredentials.getMetadataServerUrl() + SecureSessionAgent.S2A_CONFIG_ENDPOINT_POSTFIX));
341341
}
342342
}

oauth2_http/javatests/com/google/auth/oauth2/S2AConfigTest.java renamed to oauth2_http/javatests/com/google/auth/oauth2/SecureSessionAgentConfigTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
import org.junit.runner.RunWith;
3838
import org.junit.runners.JUnit4;
3939

40-
/** Test cases for {@link S2AConfig}. */
40+
/** Test cases for {@linkSecureSessionAgentConfig}. */
4141
@RunWith(JUnit4.class)
42-
public class S2AConfigTest {
42+
public class SecureSessionAgentConfigTest {
4343
private static final String S2A_PLAINTEXT_ADDRESS = "plaintext";
4444
private static final String S2A_MTLS_ADDRESS = "mtls";
4545

4646
@Test
4747
public void createS2AConfig_success() {
48-
S2AConfig config =
49-
S2AConfig.createBuilder()
48+
SecureSessionAgentConfig config =
49+
SecureSessionAgentConfig.createBuilder()
5050
.setPlaintextAddress(S2A_PLAINTEXT_ADDRESS)
5151
.setMtlsAddress(S2A_MTLS_ADDRESS)
5252
.build();
@@ -56,7 +56,7 @@ public void createS2AConfig_success() {
5656

5757
@Test
5858
public void createEmptyS2AConfig_success() {
59-
S2AConfig config = S2AConfig.createBuilder().build();
59+
SecureSessionAgentConfig config = SecureSessionAgentConfig.createBuilder().build();
6060
assertTrue(config.getPlaintextAddress().isEmpty());
6161
assertTrue(config.getMtlsAddress().isEmpty());
6262
}

oauth2_http/javatests/com/google/auth/oauth2/S2ATest.java renamed to oauth2_http/javatests/com/google/auth/oauth2/SecureSessionAgentTest.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
import org.junit.runner.RunWith;
4141
import org.junit.runners.JUnit4;
4242

43-
/** Test cases for {@link S2A}. */
43+
/** Test cases for {@link SecureSessionAgent}. */
4444
@RunWith(JUnit4.class)
45-
public class S2ATest {
45+
public class SecureSessionAgentTest {
4646

4747
private static final String INVALID_JSON_KEY = "invalid_key";
4848
private static final String S2A_PLAINTEXT_ADDRESS = "plaintext";
@@ -53,14 +53,15 @@ public void getS2AAddress_validAddress() {
5353
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
5454
transportFactory.transport.setS2AContentMap(
5555
ImmutableMap.of(
56-
S2A.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
56+
SecureSessionAgent.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
5757
S2A_PLAINTEXT_ADDRESS,
58-
S2A.S2A_MTLS_ADDRESS_JSON_KEY,
58+
SecureSessionAgent.S2A_MTLS_ADDRESS_JSON_KEY,
5959
S2A_MTLS_ADDRESS));
6060
transportFactory.transport.setRequestStatusCode(HttpStatusCodes.STATUS_CODE_OK);
6161

62-
S2A s2aUtils = S2A.newBuilder().setHttpTransportFactory(transportFactory).build();
63-
S2AConfig config = s2aUtils.getConfigFromMDS();
62+
SecureSessionAgent s2aUtils =
63+
SecureSessionAgent.newBuilder().setHttpTransportFactory(transportFactory).build();
64+
SecureSessionAgentConfig config = s2aUtils.getConfigFromMDS();
6465
String plaintextS2AAddress = config.getPlaintextAddress();
6566
String mtlsS2AAddress = config.getMtlsAddress();
6667
assertEquals(S2A_PLAINTEXT_ADDRESS, plaintextS2AAddress);
@@ -72,15 +73,16 @@ public void getS2AAddress_queryEndpointResponseErrorCode_emptyAddress() {
7273
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
7374
transportFactory.transport.setS2AContentMap(
7475
ImmutableMap.of(
75-
S2A.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
76+
SecureSessionAgent.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
7677
S2A_PLAINTEXT_ADDRESS,
77-
S2A.S2A_MTLS_ADDRESS_JSON_KEY,
78+
SecureSessionAgent.S2A_MTLS_ADDRESS_JSON_KEY,
7879
S2A_MTLS_ADDRESS));
7980
transportFactory.transport.setRequestStatusCode(
8081
HttpStatusCodes.STATUS_CODE_SERVICE_UNAVAILABLE);
8182

82-
S2A s2aUtils = S2A.newBuilder().setHttpTransportFactory(transportFactory).build();
83-
S2AConfig config = s2aUtils.getConfigFromMDS();
83+
SecureSessionAgent s2aUtils =
84+
SecureSessionAgent.newBuilder().setHttpTransportFactory(transportFactory).build();
85+
SecureSessionAgentConfig config = s2aUtils.getConfigFromMDS();
8486
String plaintextS2AAddress = config.getPlaintextAddress();
8587
String mtlsS2AAddress = config.getMtlsAddress();
8688
assertTrue(plaintextS2AAddress.isEmpty());
@@ -92,15 +94,16 @@ public void getS2AAddress_queryEndpointResponseEmpty_emptyAddress() {
9294
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
9395
transportFactory.transport.setS2AContentMap(
9496
ImmutableMap.of(
95-
S2A.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
97+
SecureSessionAgent.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
9698
S2A_PLAINTEXT_ADDRESS,
97-
S2A.S2A_MTLS_ADDRESS_JSON_KEY,
99+
SecureSessionAgent.S2A_MTLS_ADDRESS_JSON_KEY,
98100
S2A_MTLS_ADDRESS));
99101
transportFactory.transport.setRequestStatusCode(HttpStatusCodes.STATUS_CODE_OK);
100102
transportFactory.transport.setEmptyContent(true);
101103

102-
S2A s2aUtils = S2A.newBuilder().setHttpTransportFactory(transportFactory).build();
103-
S2AConfig config = s2aUtils.getConfigFromMDS();
104+
SecureSessionAgent s2aUtils =
105+
SecureSessionAgent.newBuilder().setHttpTransportFactory(transportFactory).build();
106+
SecureSessionAgentConfig config = s2aUtils.getConfigFromMDS();
104107
String plaintextS2AAddress = config.getPlaintextAddress();
105108
String mtlsS2AAddress = config.getMtlsAddress();
106109
assertTrue(plaintextS2AAddress.isEmpty());
@@ -114,12 +117,13 @@ public void getS2AAddress_queryEndpointResponseInvalidPlaintextJsonKey_plaintext
114117
ImmutableMap.of(
115118
INVALID_JSON_KEY,
116119
S2A_PLAINTEXT_ADDRESS,
117-
S2A.S2A_MTLS_ADDRESS_JSON_KEY,
120+
SecureSessionAgent.S2A_MTLS_ADDRESS_JSON_KEY,
118121
S2A_MTLS_ADDRESS));
119122
transportFactory.transport.setRequestStatusCode(HttpStatusCodes.STATUS_CODE_OK);
120123

121-
S2A s2aUtils = S2A.newBuilder().setHttpTransportFactory(transportFactory).build();
122-
S2AConfig config = s2aUtils.getConfigFromMDS();
124+
SecureSessionAgent s2aUtils =
125+
SecureSessionAgent.newBuilder().setHttpTransportFactory(transportFactory).build();
126+
SecureSessionAgentConfig config = s2aUtils.getConfigFromMDS();
123127
String plaintextS2AAddress = config.getPlaintextAddress();
124128
String mtlsS2AAddress = config.getMtlsAddress();
125129
assertTrue(plaintextS2AAddress.isEmpty());
@@ -131,14 +135,15 @@ public void getS2AAddress_queryEndpointResponseInvalidMtlsJsonKey_mtlsEmptyAddre
131135
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
132136
transportFactory.transport.setS2AContentMap(
133137
ImmutableMap.of(
134-
S2A.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
138+
SecureSessionAgent.S2A_PLAINTEXT_ADDRESS_JSON_KEY,
135139
S2A_PLAINTEXT_ADDRESS,
136140
INVALID_JSON_KEY,
137141
S2A_MTLS_ADDRESS));
138142
transportFactory.transport.setRequestStatusCode(HttpStatusCodes.STATUS_CODE_OK);
139143

140-
S2A s2aUtils = S2A.newBuilder().setHttpTransportFactory(transportFactory).build();
141-
S2AConfig config = s2aUtils.getConfigFromMDS();
144+
SecureSessionAgent s2aUtils =
145+
SecureSessionAgent.newBuilder().setHttpTransportFactory(transportFactory).build();
146+
SecureSessionAgentConfig config = s2aUtils.getConfigFromMDS();
142147
String plaintextS2AAddress = config.getPlaintextAddress();
143148
String mtlsS2AAddress = config.getMtlsAddress();
144149
assertEquals(S2A_PLAINTEXT_ADDRESS, plaintextS2AAddress);

0 commit comments

Comments
 (0)