Skip to content

Commit 97b27a6

Browse files
authored
Merge pull request #221 from awslabs/core
Merge core changes for 1.3 release
2 parents fdb72e4 + 8af1e48 commit 97b27a6

File tree

138 files changed

+3728
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+3728
-455
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ release.properties
2222
dependency-reduced-pom.xml
2323
buildNumber.properties
2424
.mvn/timing.properties
25+
.gradle/
26+
gradle/
27+
build/
28+
gradlew*
2529

2630
# Exclude maven wrapper
2731
!/.mvn/wrapper/maven-wrapper.jar

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
language: java
2+
dist: trusty
23
jdk:
3-
- oraclejdk8
4-
script: mvn install
4+
- openjdk8
5+
addons:
6+
apt:
7+
update: true
8+
before_install:
9+
- wget https://services.gradle.org/distributions/gradle-5.0-bin.zip
10+
- mkdir /opt/gradle
11+
- unzip -d /opt/gradle gradle-5.0-bin.zip
12+
- export GRADLE=/opt/gradle/gradle-5.0/bin/gradle
13+
install: true
14+
script: ./travis.sh

aws-serverless-java-container-core/pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,23 @@
6969
<dependency>
7070
<groupId>org.apache.httpcomponents</groupId>
7171
<artifactId>httpmime</artifactId>
72-
<version>4.5.3</version>
72+
<version>4.5.6</version>
73+
<scope>compile</scope>
74+
</dependency>
75+
76+
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
77+
<dependency>
78+
<groupId>org.apache.httpcomponents</groupId>
79+
<artifactId>httpclient</artifactId>
80+
<version>4.5.6</version>
7381
<scope>test</scope>
7482
</dependency>
83+
<dependency>
84+
<groupId>org.apache.httpcomponents</groupId>
85+
<artifactId>httpcore</artifactId>
86+
<version>4.4.10</version>
87+
<scope>compile</scope>
88+
</dependency>
7589
</dependencies>
7690

7791
<build>
@@ -162,7 +176,7 @@
162176
<plugin>
163177
<groupId>org.owasp</groupId>
164178
<artifactId>dependency-check-maven</artifactId>
165-
<version>3.3.2</version>
179+
<version>${dependencyCheck.version}</version>
166180
<configuration>
167181
<skipProvidedScope>true</skipProvidedScope>
168182
<suppressionFiles>

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/AwsProxyExceptionHandler.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
1717
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
1818
import com.amazonaws.serverless.proxy.model.ErrorModel;
19-
import com.amazonaws.serverless.proxy.model.MultiValuedTreeMap;
19+
import com.amazonaws.serverless.proxy.model.Headers;
2020

2121
import com.fasterxml.jackson.core.JsonProcessingException;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat;
24-
import com.fasterxml.jackson.databind.ser.std.JsonValueSerializer;
2522
import org.slf4j.Logger;
2623
import org.slf4j.LoggerFactory;
2724

@@ -30,8 +27,6 @@
3027

3128
import java.io.IOException;
3229
import java.io.OutputStream;
33-
import java.util.HashMap;
34-
import java.util.Map;
3530

3631
/**
3732
* Default implementation of the <code>ExceptionHandler</code> object that returns AwsProxyResponse objects.
@@ -58,7 +53,7 @@ public class AwsProxyExceptionHandler
5853
// Variables - Private - Static
5954
//-------------------------------------------------------------
6055

61-
private static MultiValuedTreeMap<String, String> headers = new MultiValuedTreeMap<>(String.CASE_INSENSITIVE_ORDER);
56+
private static Headers headers = new Headers();
6257

6358
//-------------------------------------------------------------
6459
// Constructors

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/AwsProxySecurityContextWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import javax.ws.rs.core.SecurityContext;
2020

2121
/**
22-
* Default impolementation of <code>SecurityContextWriter</code>. Creates a SecurityContext object based on an API Gateway
22+
* Default implementation of <code>SecurityContextWriter</code>. Creates a SecurityContext object based on an API Gateway
2323
* event and the Lambda context. This returns the default <code>AwsProxySecurityContext</code> instance.
2424
*/
2525
public class AwsProxySecurityContextWriter implements SecurityContextWriter<AwsProxyRequest> {

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/ExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* handled by the client applications directly within the container and a valid HTTP response is expected. This handler
2121
* is used for exceptions thrown by the library while marshalling and unmarshalling requests and responses.
2222
*
23-
* The interface delcares two methods. A typed <code>handle</code> method for requests that are being proxied using a
23+
* The interface declares two methods. A typed <code>handle</code> method for requests that are being proxied using a
2424
* request and response type <code>LambdaContainerHandler</code>, and a stream-based
2525
* <code>handle</code> method for <a href="http://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-stream.html" target="_blank">
2626
* Lambda's <code>RequestStreamHandler</code></a>.

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/RequestReader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* object that supports requests for the AWS_PROXY integration.
2828
*
2929
* @param <RequestType> The type for the AWS Lambda event
30-
* @param <ContainerRequestType> The type for the undelying container request object
30+
* @param <ContainerRequestType> The type for the underlying container request object
3131
*/
3232
public abstract class RequestReader<RequestType, ContainerRequestType> {
3333

@@ -45,6 +45,11 @@ public abstract class RequestReader<RequestType, ContainerRequestType> {
4545
*/
4646
public static final String API_GATEWAY_STAGE_VARS_PROPERTY = "com.amazonaws.apigateway.stage.variables";
4747

48+
/**
49+
* The key for the <strong>ALB context</strong> property in the PropertiesDelegate object
50+
*/
51+
public static final String ALB_CONTEXT_PROPERTY = "com.amazonaws.alb.request.context";
52+
4853
/**
4954
* The key to store the entire API Gateway event
5055
*/

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/ResponseWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* or a <code>ResponseReader</code> implementation. For example, the Jersey library passes the response reader object to
2626
* the default implementation of this class.
2727
*
28-
* @param <ContainerResponseType> The response object expceted from the underlying container
28+
* @param <ContainerResponseType> The response object expected from the underlying container
2929
* @param <ResponseType> The type for the Lambda function return value
3030
*/
3131
public abstract class ResponseWriter<ContainerResponseType, ResponseType> {

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/SecurityUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import java.io.File;
99
import java.io.IOException;
10-
import java.util.ArrayList;
1110
import java.util.HashSet;
12-
import java.util.List;
1311
import java.util.Locale;
1412
import java.util.Set;
1513

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/jaxrs/AwsProxySecurityContext.java

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@
1212
*/
1313
package com.amazonaws.serverless.proxy.internal.jaxrs;
1414

15+
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
1516
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
1617
import com.amazonaws.serverless.proxy.model.CognitoAuthorizerClaims;
1718
import com.amazonaws.services.lambda.runtime.Context;
1819

20+
import com.fasterxml.jackson.core.type.TypeReference;
21+
1922
import javax.ws.rs.core.SecurityContext;
23+
24+
import java.io.IOException;
2025
import java.security.Principal;
26+
import java.util.Base64;
27+
import java.util.Map;
28+
29+
import static com.amazonaws.serverless.proxy.model.AwsProxyRequest.*;
30+
import static com.amazonaws.serverless.proxy.model.AwsProxyRequest.RequestSource.API_GATEWAY;
31+
2132

2233
/**
2334
* default implementation of the <code>SecurityContext</code> object. This class supports 3 API Gateway's authorization methods:
@@ -31,12 +42,15 @@ public class AwsProxySecurityContext
3142
implements SecurityContext {
3243

3344
//-------------------------------------------------------------
34-
// Constants - Private
45+
// Constants - Package
3546
//-------------------------------------------------------------
3647

37-
private static final String AUTH_SCHEME_CUSTOM = "CUSTOM_AUTHORIZER";
38-
private static final String AUTH_SCHEME_COGNITO_POOL = "COGNITO_USER_POOL";
39-
private static final String AUTH_SCHEME_AWS_IAM = "AWS_IAM";
48+
static final String AUTH_SCHEME_CUSTOM = "CUSTOM_AUTHORIZER";
49+
static final String AUTH_SCHEME_COGNITO_POOL = "COGNITO_USER_POOL";
50+
static final String AUTH_SCHEME_AWS_IAM = "AWS_IAM";
51+
52+
static final String ALB_ACESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
53+
static final String ALB_IDENTITY_HEADER = "x-amzn-oidc-identity";
4054

4155

4256
//-------------------------------------------------------------
@@ -78,7 +92,12 @@ public Principal getUserPrincipal() {
7892
if (getAuthenticationScheme().equals(AUTH_SCHEME_CUSTOM) || getAuthenticationScheme().equals(AUTH_SCHEME_AWS_IAM)) {
7993
return () -> {
8094
if (getAuthenticationScheme().equals(AUTH_SCHEME_CUSTOM)) {
81-
return event.getRequestContext().getAuthorizer().getPrincipalId();
95+
switch (event.getRequestSource()) {
96+
case API_GATEWAY:
97+
return event.getRequestContext().getAuthorizer().getPrincipalId();
98+
case ALB:
99+
return event.getMultiValueHeaders().getFirst(ALB_IDENTITY_HEADER);
100+
}
82101
} else if (getAuthenticationScheme().equals(AUTH_SCHEME_AWS_IAM)) {
83102
// if we received credentials from Cognito Federated Identities then we return the identity id
84103
if (event.getRequestContext().getIdentity().getCognitoIdentityId() != null) {
@@ -112,15 +131,24 @@ public boolean isSecure() {
112131

113132

114133
public String getAuthenticationScheme() {
115-
if (event.getRequestContext().getAuthorizer() != null && event.getRequestContext().getAuthorizer().getClaims() != null && event.getRequestContext().getAuthorizer().getClaims().getSubject() != null) {
116-
return AUTH_SCHEME_COGNITO_POOL;
117-
} else if (event.getRequestContext().getAuthorizer() != null) {
118-
return AUTH_SCHEME_CUSTOM;
119-
} else if (event.getRequestContext().getIdentity().getAccessKey() != null) {
120-
return AUTH_SCHEME_AWS_IAM;
121-
} else {
122-
return null;
134+
switch (event.getRequestSource()) {
135+
case API_GATEWAY:
136+
if (event.getRequestContext().getAuthorizer() != null && event.getRequestContext().getAuthorizer().getClaims() != null
137+
&& event.getRequestContext().getAuthorizer().getClaims().getSubject() != null) {
138+
return AUTH_SCHEME_COGNITO_POOL;
139+
} else if (event.getRequestContext().getAuthorizer() != null) {
140+
return AUTH_SCHEME_CUSTOM;
141+
} else if (event.getRequestContext().getIdentity().getAccessKey() != null) {
142+
return AUTH_SCHEME_AWS_IAM;
143+
} else {
144+
return null;
145+
}
146+
case ALB:
147+
if (event.getMultiValueHeaders().containsKey(ALB_ACESS_TOKEN_HEADER)) {
148+
return AUTH_SCHEME_CUSTOM;
149+
}
123150
}
151+
return null;
124152
}
125153

126154

0 commit comments

Comments
 (0)