Skip to content

Commit

Permalink
DXE-2981 Merge pull request #49 from akamai/release/5.1.0
Browse files Browse the repository at this point in the history
DXE-2981 Release/5.1.0
  • Loading branch information
mgwoj committed Sep 5, 2023
2 parents 24b6be0 + 6e0c451 commit 3f85113
Show file tree
Hide file tree
Showing 26 changed files with 237 additions and 29 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change log

## 5.1.0 (September 5, 2023)

### Improvements

* Add support for Apache HTTP Client version 5.

### Fixes

* Fixes for various CVE vulnerabilities by upgrading netty, dependency-check and guava libraries.
* Fixes some build errors by upgrading Jacoco library.
* Resolve various Javadoc warnings in different modules.

## 5.0.0 (January 19, 2023)

### BREAKING CHANGES
Expand Down
2 changes: 1 addition & 1 deletion edgegrid-signer-apache-http-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

This library implements [Akamai EdgeGrid Authentication](https://techdocs.akamai.com/developer/docs/authenticate-with-edgegrid) for Java.
This particular module is a binding for the [Apache HTTP Client library](https://hc.apache.org/) versions before 5.0.0.
For Apache HTTP Client >= 5.0.0 support, use `edgegrid-signer-apache-http-client5` module.
For Apache HTTP Client >= 5.0.0, use `edgegrid-signer-apache-http-client5` module.
This project contains installation and usage instructions in the [README.md](../README.md).

## Use Apache HTTP Client
Expand Down
2 changes: 1 addition & 1 deletion edgegrid-signer-apache-http-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>edgegrid-signer-parent</artifactId>
<groupId>com.akamai.edgegrid</groupId>
<version>5.0.0</version>
<version>5.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@
*/
public class ApacheHttpClientEdgeGridRequestSigner extends AbstractEdgeGridRequestSigner<HttpRequest, HttpRequest> {

/**
* Creates an EdgeGrid signer using {@link ClientCredential}.
*
* @param clientCredential a {@link ClientCredential}
*/
public ApacheHttpClientEdgeGridRequestSigner(ClientCredential clientCredential) {
super(clientCredential);
}

/**
* Creates an EdgeGrid signer using {@link ClientCredentialProvider}.
*
* @param clientCredentialProvider a {@link ClientCredentialProvider}
*/
public ApacheHttpClientEdgeGridRequestSigner(ClientCredentialProvider clientCredentialProvider) {
super(clientCredentialProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,30 @@
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.apache.http.protocol.HttpContext;

/**
* Apache HTTP Client binding for EdgeGrid route planner for computing {@link HttpRoute}.
*
* @author mgawinec@akamai.com
*/
public class ApacheHttpClientEdgeGridRoutePlanner extends SystemDefaultRoutePlanner {

private final ApacheHttpClientEdgeGridRequestSigner binding;

/**
* Creates an EdgeGrid route planner using {@link ClientCredential}.
*
* @param clientCredential a {@link ClientCredential}
*/
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredential clientCredential) {
super(ProxySelector.getDefault());
this.binding = new ApacheHttpClientEdgeGridRequestSigner(clientCredential);
}

/**
* Creates an EdgeGrid route planner using {@link ClientCredentialProvider}.
*
* @param clientCredentialProvider a {@link ClientCredentialProvider}
*/
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredentialProvider clientCredentialProvider) {
super(ProxySelector.getDefault());
this.binding = new ApacheHttpClientEdgeGridRequestSigner(clientCredentialProvider);
Expand Down
4 changes: 1 addition & 3 deletions edgegrid-signer-apache-http-client5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.akamai.edgegrid/edgegrid-signer-apache-http-client5/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.akamai.edgegrid/edgegrid-signer-apache-http-client5)
-[![Javadoc](http://www.javadoc.io/badge/com.akamai.edgegrid/edgegrid-signer-apache-http-client5.svg)](http://www.javadoc.io/doc/com.akamai.edgegrid/edgegrid-signer-apache-http-client5)

This library
implements [Akamai EdgeGrid Authentication](https://techdocs.akamai.com/developer/docs/authenticate-with-edgegrid) for
Java.
This library implements [Akamai EdgeGrid Authentication](https://techdocs.akamai.com/developer/docs/authenticate-with-edgegrid) for Java.
This particular module is a binding for the [Apache HTTP Client library version 5.x](https://hc.apache.org/).
This project contains installation and usage instructions in the [README.md](../README.md).

Expand Down
2 changes: 1 addition & 1 deletion edgegrid-signer-apache-http-client5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>edgegrid-signer-parent</artifactId>
<groupId>com.akamai.edgegrid</groupId>
<version>5.0.0</version>
<version>5.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@
*/
public class ApacheHttpClient5EdgeGridRequestSigner extends AbstractEdgeGridRequestSigner<HttpRequest, HttpRequest> {

/**
* Creates an EdgeGrid signer using {@link ClientCredential}.
*
* @param clientCredential a {@link ClientCredential}
*/
public ApacheHttpClient5EdgeGridRequestSigner(ClientCredential clientCredential) {
super(clientCredential);
}

/**
* Creates an EdgeGrid signer using {@link ClientCredentialProvider}.
*
* @param clientCredentialProvider a {@link ClientCredentialProvider}
*/
public ApacheHttpClient5EdgeGridRequestSigner(ClientCredentialProvider clientCredentialProvider) {
super(clientCredentialProvider);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
package com.akamai.edgegrid.signer.apachehttpclient5;

import com.akamai.edgegrid.signer.ClientCredential;
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.protocol.HttpContext;

import java.net.ProxySelector;

public class ApacheHttpClient5EdgeGridRoutePlanner extends SystemDefaultRoutePlanner {
/**
* Apache HTTP Client binding for EdgeGrid route planner for computing {@link HttpRoute}.
*
*/
@Contract(threading = ThreadingBehavior.STATELESS)
public class ApacheHttpClient5EdgeGridRoutePlanner implements HttpRoutePlanner {

private final ClientCredential clientCredential;

/**
* Creates an EdgeGrid route planner using {@link ClientCredential}.
*
* @param clientCredential a {@link ClientCredential}
*/
public ApacheHttpClient5EdgeGridRoutePlanner(ClientCredential clientCredential) {
super(ProxySelector.getDefault());
this.clientCredential = clientCredential;
}

@Override
protected HttpHost determineProxy(HttpHost target, HttpContext context) {
public HttpRoute determineRoute(HttpHost target, HttpContext context) throws HttpException {
var hostname = clientCredential.getHost();
int port = -1;
int port = 443;
final int pos = hostname.lastIndexOf(":");
if (pos > 0) {
try {
port = Integer.parseInt(hostname.substring(pos + 1));
if (port <= 0 || port > 65535) {
throw new NumberFormatException();
}
} catch (NumberFormatException ex) {
throw new IllegalArgumentException("Host contains invalid port number: " + hostname);
}
hostname = hostname.substring(0, pos);
}
return new HttpHost("https", hostname, port);
HttpHost host = new HttpHost("https", hostname, port);
return new HttpRoute(host, null, true);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import java.net.URISyntaxException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;

/**
* Example of use of EdgeGrid signer with Apache HTTP Client5.
Expand Down
2 changes: 1 addition & 1 deletion edgegrid-signer-async-http-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>edgegrid-signer-parent</artifactId>
<groupId>com.akamai.edgegrid</groupId>
<version>5.0.0</version>
<version>5.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,27 @@

import static org.asynchttpclient.util.MiscUtils.isNonEmpty;

/**
* Async HTTP Client binding for EdgeGrid signer for signing {@link Request}.
*
* @author mgawinec@akamai.com
*/
public class AsyncHttpClientEdgeGridRequestSigner extends AbstractEdgeGridRequestSigner<Request, RequestBuilderBase> {

/**
* Creates an EdgeGrid signer using {@link ClientCredential}.
*
* @param credential a {@link ClientCredential}
*/
public AsyncHttpClientEdgeGridRequestSigner(ClientCredential credential) {
super(credential);
}

/**
* Creates an EdgeGrid signer using {@link ClientCredentialProvider}.
*
* @param credentialProvider a {@link ClientCredentialProvider}
*/
public AsyncHttpClientEdgeGridRequestSigner(ClientCredentialProvider credentialProvider) {
super(credentialProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@
import org.asynchttpclient.RequestBuilderBase;
import org.asynchttpclient.SignatureCalculator;

/**
* Async HTTP Client binding for EdgeGrid signature calculator {@link SignatureCalculator}.
*
* @author mgawinec@akamai.com
*/
public class AsyncHttpClientEdgeGridSignatureCalculator implements SignatureCalculator {

private final AsyncHttpClientEdgeGridRequestSigner binding;

/**
* Creates an EdgeGrid signature calculator using {@link ClientCredential}.
*
* @param credential a {@link ClientCredential}
*/
public AsyncHttpClientEdgeGridSignatureCalculator(ClientCredential credential) {
this.binding = new AsyncHttpClientEdgeGridRequestSigner(credential);
}

/**
* Creates an EdgeGrid signature calculator using {@link ClientCredentialProvider}.
*
* @param credentialProvider a {@link ClientCredentialProvider}
*/
public AsyncHttpClientEdgeGridSignatureCalculator(ClientCredentialProvider credentialProvider) {
this.binding = new AsyncHttpClientEdgeGridRequestSigner(credentialProvider);
}
Expand Down
2 changes: 1 addition & 1 deletion edgegrid-signer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>edgegrid-signer-parent</artifactId>
<groupId>com.akamai.edgegrid</groupId>
<version>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>edgegrid-signer-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* offers a more configurable way to retrieve credentials any way the user wants. </p>
*
* @param <RequestT> a type of HTTP client specific request.
* @param <MutableRequestT> a type of HTTP client request to update.
* @author mgawinec@akamai.com
* @author mmeyer@akamai.com
*/
Expand Down Expand Up @@ -64,7 +65,12 @@ public AbstractEdgeGridRequestSigner(ClientCredentialProvider clientCredentialPr
this.edgeGridSigner = new EdgeGridV1Signer();
}


/**
* Retrieves {@link ClientCredentialProvider}.
*
* @return {@link ClientCredentialProvider}
*
*/
public final ClientCredentialProvider getClientCredentialProvider() {
return clientCredentialProvider;
}
Expand Down Expand Up @@ -100,6 +106,9 @@ public void sign(RequestT request, MutableRequestT requestToUpdate) throws Reque

/**
* Returns Request-URI of an original request.
*
* @param request an HTTP client-specific request
* @return a {@link URI} of {@code request}
*/
protected abstract URI requestUri(RequestT request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,62 @@ public boolean equals(Object o) {
return compareTo(that) == 0;
}

/**
* Retrieves access token.
*
* @return accessToken
*
*/
public String getAccessToken() {
return accessToken;
}

/**
* Retrieves client secret.
*
* @return clientSecret
*
*/
public String getClientSecret() {
return clientSecret;
}

/**
* Retrieves client token.
*
* @return clientToken
*
*/
public String getClientToken() {
return clientToken;
}

/**
* Retrieves set of headers for signing.
*
* @return headersToSign
*
*/
public Set<String> getHeadersToSign() {
return headersToSign;
}

/**
* Retrieves host.
*
* @return host
*
*/
public String getHost() {
return host;
}

/**
* Defines maximum body size defined in bytes.
*
* @return maxBodySize
*
*/
public int getMaxBodySize() {
if (maxBodySize == null) {
return DEFAULT_MAX_BODY_SIZE_IN_BYTES;
Expand All @@ -141,6 +177,10 @@ public String toString() {
.toString();
}

/**
* Defines {@link ClientCredentialBuilder} which is used to build instance of {@link ClientCredential}.
*
*/
public static class ClientCredentialBuilder {
private String accessToken;
private String clientSecret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class DefaultClientCredentialProvider implements ClientCredentialProvider

private ClientCredential clientCredential;

/**
* Creates a {@link DefaultClientCredentialProvider} using {@link ClientCredential}.
*
* @param clientCredential a {@link ClientCredential}
*/
public DefaultClientCredentialProvider(ClientCredential clientCredential) {
this.clientCredential = Objects.requireNonNull(clientCredential, "clientCredential cannot be null");
}
Expand Down
Loading

0 comments on commit 3f85113

Please sign in to comment.