diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayCustomAuthorizerEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayCustomAuthorizerEvent.java new file mode 100644 index 00000000..72883319 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayCustomAuthorizerEvent.java @@ -0,0 +1,59 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * The API Gateway customer authorizer event object as described - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html + * + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class APIGatewayCustomAuthorizerEvent { + + private String version; + private String type; + private String methodArn; + private String identitySource; + private String authorizationToken; + private String resource; + private String path; + private String httpMethod; + private Map headers; + private Map queryStringParameters; + private Map pathParameters; + private Map stageVariables; + private RequestContext requestContext; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class RequestContext { + private String path; + private String accountId; + private String resourceId; + private String stage; + private String requestId; + private Identity identity; + private String resourcePath; + private String httpMethod; + private String apiId; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Identity { + private String apiKey; + private String sourceIp; + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEvent.java new file mode 100644 index 00000000..6abfe051 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEvent.java @@ -0,0 +1,80 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import java.time.Instant; +import java.util.List; +import java.util.Map; + +/** + * The V2 API Gateway customer authorizer event object as described - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html + * + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class APIGatewayV2CustomAuthorizerEvent { + + private String version; + private String type; + private String routeArn; + private List identitySource; + private String routeKey; + private String rawPath; + private String rawQueryString; + private List cookies; + private Map headers; + private Map queryStringParameters; + private RequestContext requestContext; + private Map pathParameters; + private Map stageVariables; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class RequestContext { + + private static DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MMM/yyyy:HH:mm:ss Z"); + + private String accountId; + private String apiId; + private String domainName; + private String domainPrefix; + private Http http; + private String requestId; + private String routeKey; + private String stage; + private String time; + private long timeEpoch; + + public Instant getTimeEpoch() { + return Instant.ofEpochMilli(timeEpoch); + } + + public DateTime getTime() { + return fmt.parseDateTime(time); + } + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class Http { + + private String method; + private String path; + private String protocol; + private String sourceIp; + private String userAgent; + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SimpleIAMPolicyResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SimpleIAMPolicyResponse.java new file mode 100644 index 00000000..030a1468 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SimpleIAMPolicyResponse.java @@ -0,0 +1,23 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * The simplified IAM Policy response object as described in https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html + * + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class SimpleIAMPolicyResponse { + + private boolean isAuthorized; + private Map context; +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java new file mode 100644 index 00000000..8f1662cd --- /dev/null +++ b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java @@ -0,0 +1,36 @@ +package com.amazonaws.services.lambda.runtime.events; + +import org.junit.jupiter.api.Test; + +import java.time.Instant; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class APIGatewayV2CustomAuthorizerEventTest { + + private static final long TIME_EPOCH = 1601306426515L; + private static final String TIME = "28/Sep/2020:15:14:43 +0000"; + + @Test + public void testEpochLongAsAnInstant() { + APIGatewayV2CustomAuthorizerEvent customAuthorizerEvent = APIGatewayV2CustomAuthorizerEvent.builder() + .withRequestContext(APIGatewayV2CustomAuthorizerEvent.RequestContext.builder() + .withTimeEpoch(TIME_EPOCH) + .build()) + .build(); + + assertEquals(Instant.ofEpochMilli(1601306426515L), customAuthorizerEvent.getRequestContext().getTimeEpoch()); + } + + @Test + public void testTimeStringAsDateTime() { + APIGatewayV2CustomAuthorizerEvent customAuthorizerEvent = APIGatewayV2CustomAuthorizerEvent.builder() + .withRequestContext(APIGatewayV2CustomAuthorizerEvent.RequestContext.builder() + .withTime(TIME) + .build()) + .build(); + + assertNotNull(customAuthorizerEvent.getRequestContext().getTime()); + } +} \ No newline at end of file