diff --git a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/jaxrs/AwsProxySecurityContext.java b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/jaxrs/AwsProxySecurityContext.java index cba3a79c4..8a61a95dd 100644 --- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/jaxrs/AwsProxySecurityContext.java +++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/jaxrs/AwsProxySecurityContext.java @@ -71,7 +71,7 @@ public Principal getUserPrincipal() { } else if (getAuthenticationScheme().equals(AUTH_SCHEME_AWS_IAM)) { return event.getRequestContext().getIdentity().getUserArn(); } else if (getAuthenticationScheme().equals(AUTH_SCHEME_COGNITO_POOL)) { - return event.getRequestContext().getIdentity().getCognitoIdentityId(); + return event.getRequestContext().getAuthorizer().getClaims().getSubject(); } return null; @@ -90,7 +90,7 @@ public boolean isSecure() { public String getAuthenticationScheme() { - if (event.getRequestContext().getIdentity().getCognitoAuthenticationType() != null) { + if (event.getRequestContext().getAuthorizer().getClaims() != null && event.getRequestContext().getAuthorizer().getClaims().getSubject() != null) { return AUTH_SCHEME_COGNITO_POOL; } else if (event.getRequestContext().getAuthorizer() != null) { return AUTH_SCHEME_CUSTOM; diff --git a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/model/CognitoAuthorizerClaims.java b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/model/CognitoAuthorizerClaims.java index dd380c137..d064db417 100644 --- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/model/CognitoAuthorizerClaims.java +++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/model/CognitoAuthorizerClaims.java @@ -59,7 +59,7 @@ public class CognitoAuthorizerClaims { private String exp; private String iat; - private String getSubject() { return this.subject; } + public String getSubject() { return this.subject; } public void setSubject(String subject) { this.subject = subject; @@ -145,6 +145,12 @@ public void setExp(String expiration) { this.exp = expiration; } + + /** + * Returns the expiration time for the token as a ZonedDateTime from the exp property + * of the token. + * @return The parsed expiration time for the token. + */ public ZonedDateTime getExpirationTime() { return ZonedDateTime.from(TOKEN_DATE_FORMATTER.parse(getExp())); } @@ -159,6 +165,12 @@ public void setIat(String issuedAt) { this.iat = issuedAt; } + + /** + * Returns the parsed issued time for the token as a ZonedDateTime object. This is taken from the iat + * property of the token. + * @return The parsed issue time of the token + */ public ZonedDateTime getIssueTime() { return ZonedDateTime.from((TOKEN_DATE_FORMATTER.parse(getIat()))); }