Skip to content

Commit 5dc8339

Browse files
author
Aaron Anderson
committed
initial commit
0 parents  commit 5dc8339

File tree

5 files changed

+534
-0
lines changed

5 files changed

+534
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
.settings
3+
.classpath
4+
.project

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# jax-rs-aws-signerv4
2+
After scouring the Internet for a simple [AWS Signature Version 4 Signing](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html) java library with limited dependencies and support for JAX-RS 2.0 and not finding one I decided to write one.
3+
4+
The main motivation for this library is to support JAX-RS calls to an AWS elasticsearch instance. the AWS Java API 2.0 has a client class for managing search domains but nothing for actually accessing the service.
5+
6+
Previously I had used the AWS SDK 2.0 preview to create a [S3 presigning URL](https://gist.github.com/aaronanderson/f9e2806cc5e2c18fab4d7e60c589d160) Java utility but the current SDK codebase is geared for autogenerated clients and it is nearly impossible to write a client by and that initializes all the prerequists. After examining several other Java AWS signinging implementations and studying the AWS signing documentation I was able to develop a solution that meets my requirements. As an added bonus I was able to add presigning capabilities for S3 with little effort.
7+
8+
## Configuration
9+
Create an instance of the AWSSignerClientRequestFilter class using the builder. Provide the AWS
10+
```
11+
DefaultCredentialsProvider provider = DefaultCredentialsProvider.create();
12+
credentials = provider.getCredentials();
13+
AWSSignerClientRequestFilter.Builder builder = AWSSignerClientRequestFilter.builder().accessKeyID(credentials.accessKeyId()).secretAccessKey(credentials.secretAccessKey()).regionName("us-west-1").serviceName("es");
14+
if (AwsSessionCredentials.class.isAssignableFrom(credentials.getClass())) {
15+
builder.sessionToken(() -> (((AwsSessionCredentials) credentials).sessionToken()));
16+
}
17+
AWSSignerClientRequestFilter signer = builder.build();
18+
```
19+
Note I have not actually testes the token session feature but it should work.
20+
##JAX-RS
21+
Just register the filter/interceptor
22+
```
23+
client.register(signer);
24+
```
25+
##Pre-Sign
26+
Pass in the method, requestURI, and expiration duration
27+
```
28+
URI presigned = signer.presign("GET", new URI("https://some-s3-bucket.s3-us-west-1.amazonaws.com/intworkspace.json"), Duration.ofDays(1));
29+
```

pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>jax-rs-aws-signerv4</groupId>
4+
<artifactId>jax-rs-aws-signerv4</artifactId>
5+
<version>1.0-SNAPSHOT</version>
6+
7+
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
</properties>
13+
14+
<dependencies>
15+
16+
<dependency>
17+
<groupId>software.amazon.awssdk</groupId>
18+
<artifactId>core</artifactId>
19+
<version>2.0.0-preview-7</version>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.apache.johnzon</groupId>
24+
<artifactId>johnzon-jaxrs</artifactId>
25+
<version>1.1.5</version>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>org.apache.geronimo.specs</groupId>
30+
<artifactId>geronimo-json_1.1_spec</artifactId>
31+
<version>1.0</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.apache.cxf</groupId>
36+
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
37+
<version>3.2.1</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.apache.cxf</groupId>
42+
<artifactId>cxf-rt-rs-client</artifactId>
43+
<version>3.2.1</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>junit</groupId>
48+
<artifactId>junit</artifactId>
49+
<version>4.12</version>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
</project>

0 commit comments

Comments
 (0)