Skip to content

Commit

Permalink
Bug fixes and comments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sapessi committed Apr 20, 2017
1 parent 40c6069 commit 4f1e773
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,6 +145,12 @@ public void setExp(String expiration) {
this.exp = expiration;
}


/**
* Returns the expiration time for the token as a <code>ZonedDateTime</code> from the <code>exp</code> property
* of the token.
* @return The parsed expiration time for the token.
*/
public ZonedDateTime getExpirationTime() {
return ZonedDateTime.from(TOKEN_DATE_FORMATTER.parse(getExp()));
}
Expand All @@ -159,6 +165,12 @@ public void setIat(String issuedAt) {
this.iat = issuedAt;
}


/**
* Returns the parsed issued time for the token as a <code>ZonedDateTime</code> object. This is taken from the <code>iat</code>
* property of the token.
* @return The parsed issue time of the token
*/
public ZonedDateTime getIssueTime() {
return ZonedDateTime.from((TOKEN_DATE_FORMATTER.parse(getIat())));
}
Expand Down

0 comments on commit 4f1e773

Please sign in to comment.