Skip to content

Commit 2036ea0

Browse files
DXE-4123 Merge pull request #55 from akamai/release/6.0.0
2 parents 79db8dc + 2c1248f commit 2036ea0

File tree

22 files changed

+262
-306
lines changed

22 files changed

+262
-306
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Change log
22

3+
## 6.0.0 (August 21, 2024)
4+
5+
### BREAKING CHANGES
6+
7+
* Replaced deprecated `ApacheHttpTransport` with `com.google.api.client.http.apache.v2.ApacheHttpTransport` in `edgegrid-signer-google-http-client`.
8+
* Updated `README.md` for `edgegrid-signer-google-http-client` to include changes in the instructions for signing HTTP requests with specified client credentials.
9+
10+
### Improvements
11+
12+
* Add support for `ProxySelector` in `ApacheHttpClientEdgeGridRoutePlanner` to enable the use of custom proxy servers.
13+
14+
### Fixes
15+
16+
* Fixes for various vulnerabilities by upgrading `grpc-context`, `netty` and `commons-configuration2`.
17+
* Fixed issue when path param is an url for rest assured
18+
19+
320
## 5.1.1 (December 6, 2023)
421

522
### Fixes

edgegrid-signer-apache-http-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>edgegrid-signer-parent</artifactId>
88
<groupId>com.akamai.edgegrid</groupId>
9-
<version>5.1.1</version>
9+
<version>6.0.0</version>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
1212

edgegrid-signer-apache-http-client/src/main/java/com/akamai/edgegrid/signer/apachehttpclient/ApacheHttpClientEdgeGridRoutePlanner.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ public class ApacheHttpClientEdgeGridRoutePlanner extends SystemDefaultRoutePlan
4343
* @param clientCredential a {@link ClientCredential}
4444
*/
4545
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredential clientCredential) {
46-
super(ProxySelector.getDefault());
46+
this(clientCredential, ProxySelector.getDefault());
47+
}
48+
49+
/**
50+
* Creates an EdgeGrid route planner using {@link ClientCredential}.
51+
*
52+
* @param clientCredential a {@link ClientCredential}
53+
* @param proxySelector a {@link ProxySelector}
54+
*/
55+
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredential clientCredential, ProxySelector proxySelector) {
56+
super(proxySelector);
4757
this.binding = new ApacheHttpClientEdgeGridRequestSigner(clientCredential);
4858
}
4959

@@ -53,7 +63,17 @@ public ApacheHttpClientEdgeGridRoutePlanner(ClientCredential clientCredential) {
5363
* @param clientCredentialProvider a {@link ClientCredentialProvider}
5464
*/
5565
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredentialProvider clientCredentialProvider) {
56-
super(ProxySelector.getDefault());
66+
this(clientCredentialProvider, ProxySelector.getDefault());
67+
}
68+
69+
/**
70+
* Creates an EdgeGrid route planner using {@link ClientCredentialProvider}.
71+
*
72+
* @param clientCredentialProvider a {@link ClientCredentialProvider}
73+
* @param proxySelector a {@link ProxySelector}
74+
*/
75+
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredentialProvider clientCredentialProvider, ProxySelector proxySelector) {
76+
super(proxySelector);
5777
this.binding = new ApacheHttpClientEdgeGridRequestSigner(clientCredentialProvider);
5878
}
5979

edgegrid-signer-apache-http-client/src/test/java/com/akamai/edgegrid/signer/apachehttpclient/RestAssuredIntegrationTest.java

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@
3535
import java.io.ByteArrayInputStream;
3636
import java.io.File;
3737
import java.io.IOException;
38+
import java.net.InetSocketAddress;
39+
import java.net.Proxy;
40+
import java.net.ProxySelector;
41+
import java.net.SocketAddress;
42+
import java.net.URI;
3843
import java.net.URISyntaxException;
3944
import java.nio.charset.StandardCharsets;
4045
import java.util.List;
46+
import java.util.ArrayList;
4147

4248
import io.restassured.RestAssured;
4349
import io.restassured.config.HttpClientConfig;
@@ -74,7 +80,6 @@ public class RestAssuredIntegrationTest {
7480
WireMockServer wireMockServer = new WireMockServer(wireMockConfig().httpsPort(SERVICE_MOCK_PORT));
7581

7682

77-
7883
@BeforeClass
7984
public void setUp() {
8085
wireMockServer.start();
@@ -114,6 +119,33 @@ public void signAgainFollowedRedirects() throws URISyntaxException, IOException
114119
Matchers.not(CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization"))));
115120
}
116121

122+
@Test
123+
public void signAgainFollowedRedirectsWithProxy() throws URISyntaxException, IOException {
124+
125+
wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources"))
126+
.withHeader("Authorization", matching(".*"))
127+
.withHeader("Host", equalTo(SERVICE_MOCK))
128+
.willReturn(aResponse()
129+
.withStatus(302)
130+
.withHeader("Location", "/billing-usage/v1/reportSources/alternative")));
131+
132+
wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative"))
133+
.withHeader("Authorization", matching(".*"))
134+
.withHeader("Host", equalTo(SERVICE_MOCK))
135+
.willReturn(aResponse()
136+
.withStatus(200)
137+
.withHeader("Content-Type", "text/xml")
138+
.withBody("<response>Some content</response>")));
139+
140+
getBaseRequestSpecificationWithCustomProxy()
141+
.get("/billing-usage/v1/reportSources")
142+
.then().statusCode(200);
143+
144+
List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern
145+
.everything()).getRequests();
146+
MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Authorization"),
147+
Matchers.not(CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization"))));
148+
}
117149

118150

119151
@Test
@@ -224,7 +256,7 @@ public void signEachRequestWithAbsolutePath() throws URISyntaxException, IOExcep
224256
.withStatus(200)));
225257

226258
getBaseRequestSpecification()
227-
.get("https://" + SERVICE_MOCK+ "/billing-usage/v1/reportSources")
259+
.get("https://" + SERVICE_MOCK + "/billing-usage/v1/reportSources")
228260
.then().statusCode(200);
229261
}
230262

@@ -277,6 +309,13 @@ private RequestSpecification getBaseRequestSpecification() {
277309
.baseUri("https://" + SERVICE_MOCK);
278310
}
279311

312+
private RequestSpecification getBaseRequestSpecificationWithCustomProxy() {
313+
return RestAssured.given()
314+
.config(getRestAssuredConfigWithCustomProxy(credential, new CustomProxySelector()))
315+
.relaxedHTTPSValidation()
316+
.baseUri("https://" + SERVICE_MOCK);
317+
}
318+
280319

281320
private static RestAssuredConfig getRestAssuredConfig(final ClientCredential credential) {
282321
return RestAssuredConfig.config().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(new HttpClientConfig.HttpClientFactory() {
@@ -290,4 +329,41 @@ public HttpClient createHttpClient() {
290329
}));
291330
}
292331

332+
private static RestAssuredConfig getRestAssuredConfigWithCustomProxy(final ClientCredential credential, ProxySelector proxySelector) {
333+
return RestAssuredConfig.config().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(new HttpClientConfig.HttpClientFactory() {
334+
@Override
335+
public HttpClient createHttpClient() {
336+
final DefaultHttpClient client = new DefaultHttpClient();
337+
client.addRequestInterceptor(new ApacheHttpClientEdgeGridInterceptor(credential));
338+
client.setRoutePlanner(new ApacheHttpClientEdgeGridRoutePlanner(credential, proxySelector));
339+
return client;
340+
}
341+
}));
342+
}
343+
344+
class CustomProxySelector extends ProxySelector {
345+
346+
private List<Proxy> proxies;
347+
348+
public CustomProxySelector() {
349+
// Define a proxy
350+
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080));
351+
proxies = new ArrayList<>();
352+
proxies.add(proxy);
353+
}
354+
355+
@Override
356+
public List<Proxy> select(URI uri) {
357+
// Return the proxy list
358+
if (uri == null) {
359+
throw new IllegalArgumentException("URI can't be null.");
360+
}
361+
return proxies;
362+
}
363+
364+
@Override
365+
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
366+
// No implementation needed
367+
}
368+
}
293369
}

edgegrid-signer-apache-http-client5/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>edgegrid-signer-parent</artifactId>
88
<groupId>com.akamai.edgegrid</groupId>
9-
<version>5.1.1</version>
9+
<version>6.0.0</version>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
1212

edgegrid-signer-async-http-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>edgegrid-signer-parent</artifactId>
77
<groupId>com.akamai.edgegrid</groupId>
8-
<version>5.1.1</version>
8+
<version>6.0.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

edgegrid-signer-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>edgegrid-signer-parent</artifactId>
88
<groupId>com.akamai.edgegrid</groupId>
9-
<version>5.1.1</version>
9+
<version>6.0.0</version>
1010
</parent>
1111

1212
<artifactId>edgegrid-signer-core</artifactId>

edgegrid-signer-core/src/main/java/com/akamai/edgegrid/signer/AbstractEdgeGridRequestSigner.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ public AbstractEdgeGridRequestSigner(ClientCredential clientCredential) {
6262
*/
6363
public AbstractEdgeGridRequestSigner(ClientCredentialProvider clientCredentialProvider) {
6464
this.clientCredentialProvider = clientCredentialProvider;
65-
this.edgeGridSigner = new EdgeGridV1Signer();
65+
this.edgeGridSigner = createEdgeGridSigner();
66+
}
67+
68+
/**
69+
* Returns new instance of EdgeGridV1Signer.
70+
*
71+
* @return a {@link EdgeGridV1Signer} new instance
72+
*/
73+
protected EdgeGridV1Signer createEdgeGridSigner() {
74+
return new EdgeGridV1Signer();
6675
}
6776

6877
/**

edgegrid-signer-core/src/main/java/com/akamai/edgegrid/signer/EdgeGridV1Signer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,23 @@ public EdgeGridV1Signer() {
110110
*/
111111
public String getSignature(Request request, ClientCredential credential)
112112
throws RequestSigningException {
113-
return getSignature(request, credential, System.currentTimeMillis(), generateNonce());
113+
return getSignature(request, credential, getTimestamp(), getNonce());
114+
}
115+
116+
/**
117+
* Returns timestamp needed for signing
118+
* @return returns current time stamp
119+
*/
120+
protected long getTimestamp() {
121+
return System.currentTimeMillis();
122+
}
123+
124+
/**
125+
* Returns nonce needed for signing
126+
* @return returns generated nonce
127+
*/
128+
protected String getNonce() {
129+
return generateNonce();
114130
}
115131

116132
private static String generateNonce() {

0 commit comments

Comments
 (0)