Skip to content

Commit

Permalink
feat: populate certain attributes when creating jwt auth user from token
Browse files Browse the repository at this point in the history
OCD-4721
  • Loading branch information
tmy1313 committed Nov 25, 2024
1 parent 76a43cb commit e9c77c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import gov.healthit.chpl.auth.jwt.JWTConsumer;
import gov.healthit.chpl.auth.user.JWTAuthenticatedUser;
import gov.healthit.chpl.dao.auth.UserDAO;
import gov.healthit.chpl.domain.auth.User;
import gov.healthit.chpl.exception.JWTValidationException;
import gov.healthit.chpl.exception.MultipleUserAccountsException;
import gov.healthit.chpl.exception.UserRetrievalException;
import gov.healthit.chpl.user.cognito.CognitoApiWrapper;
import lombok.extern.log4j.Log4j2;

Expand Down Expand Up @@ -38,7 +40,21 @@ public JWTAuthenticatedUser getAuthenticatedUser(String jwt) throws JWTValidatio
//If SSO is on, try to validate the jwt using the Cognito converter
if (ff4j.check(FeatureList.SSO)) {
user = cognitoJwtUserConverter.getAuthenticatedUser(jwt);
} else {
if (user != null) {
try {
//Set some values not avail in the Cognito Access Token that were avail in the CHPL token
User cognitoUser = cognitoApiWrapper.getUserInfo(user.getCognitoId());
user.setEmail(cognitoUser.getEmail());
user.setSubjectName(cognitoUser.getEmail());
user.setFullName(cognitoUser.getFullName());
} catch (UserRetrievalException e) {
throw new JWTValidationException("Could not locate the Cognito user id");
}
}
}

//If SSO is off or jwt cannot be converted using the Cognito converter, use the CHP converter
if (user == null) {
user = chplJwtUserConverter.getAuthenticatedUser(jwt);
}
return user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public User getUserInfo(UUID cognitoId) throws UserRetrievalException {
return createUserFromGetUserResponse(response);
}

@CachePut(CacheNames.COGNITO_USERS)
public User getUserInfo(String email) throws UserRetrievalException {
AdminGetUserRequest request = AdminGetUserRequest.builder()
.userPoolId(userPoolId)
Expand All @@ -197,7 +198,10 @@ public User getUserInfo(String email) throws UserRetrievalException {
}


<<<<<<< Updated upstream
@CachePut(CacheNames.COGNITO_USERS)
=======
>>>>>>> Stashed changes
public User getUserNoCache(UUID cognitoId) throws UserRetrievalException {
AdminGetUserRequest request = AdminGetUserRequest.builder()
.userPoolId(userPoolId)
Expand Down Expand Up @@ -281,6 +285,7 @@ public void setUserPassword(String userName, String password, Boolean permanent)
}
}


public AdminAddUserToGroupResponse addUserToGroup(String email, String groupName) {
AdminAddUserToGroupRequest request = AdminAddUserToGroupRequest.builder()
.userPoolId(userPoolId)
Expand Down

0 comments on commit e9c77c7

Please sign in to comment.