Skip to content

Commit 4f1e773

Browse files
committed
Bug fixes and comments
Fixed the principal id in the JaxRs security context to read the subject property from the user pools authorizer claims. Fixed a bug in the Claims object (private getSubject method). Added some comments to the `ZonedDateTime` methods in the claims object. This should completely address #24.
1 parent 40c6069 commit 4f1e773

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Principal getUserPrincipal() {
7171
} else if (getAuthenticationScheme().equals(AUTH_SCHEME_AWS_IAM)) {
7272
return event.getRequestContext().getIdentity().getUserArn();
7373
} else if (getAuthenticationScheme().equals(AUTH_SCHEME_COGNITO_POOL)) {
74-
return event.getRequestContext().getIdentity().getCognitoIdentityId();
74+
return event.getRequestContext().getAuthorizer().getClaims().getSubject();
7575
}
7676

7777
return null;
@@ -90,7 +90,7 @@ public boolean isSecure() {
9090

9191

9292
public String getAuthenticationScheme() {
93-
if (event.getRequestContext().getIdentity().getCognitoAuthenticationType() != null) {
93+
if (event.getRequestContext().getAuthorizer().getClaims() != null && event.getRequestContext().getAuthorizer().getClaims().getSubject() != null) {
9494
return AUTH_SCHEME_COGNITO_POOL;
9595
} else if (event.getRequestContext().getAuthorizer() != null) {
9696
return AUTH_SCHEME_CUSTOM;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class CognitoAuthorizerClaims {
5959
private String exp;
6060
private String iat;
6161

62-
private String getSubject() { return this.subject; }
62+
public String getSubject() { return this.subject; }
6363

6464
public void setSubject(String subject) {
6565
this.subject = subject;
@@ -145,6 +145,12 @@ public void setExp(String expiration) {
145145
this.exp = expiration;
146146
}
147147

148+
149+
/**
150+
* Returns the expiration time for the token as a <code>ZonedDateTime</code> from the <code>exp</code> property
151+
* of the token.
152+
* @return The parsed expiration time for the token.
153+
*/
148154
public ZonedDateTime getExpirationTime() {
149155
return ZonedDateTime.from(TOKEN_DATE_FORMATTER.parse(getExp()));
150156
}
@@ -159,6 +165,12 @@ public void setIat(String issuedAt) {
159165
this.iat = issuedAt;
160166
}
161167

168+
169+
/**
170+
* Returns the parsed issued time for the token as a <code>ZonedDateTime</code> object. This is taken from the <code>iat</code>
171+
* property of the token.
172+
* @return The parsed issue time of the token
173+
*/
162174
public ZonedDateTime getIssueTime() {
163175
return ZonedDateTime.from((TOKEN_DATE_FORMATTER.parse(getIat())));
164176
}

0 commit comments

Comments
 (0)