in services/shared-services/user-management-service/src/main/java/com/amazonaws/saas/eks/UserManagementService.java [50:89]
public User createUser(TenantUserDto tenantUserDto, User user) {
AWSCognitoIdentityProvider cognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder.defaultClient();
AdminCreateUserResult createUserResult = null;
if(tenantUserDto!=null && tenantUserDto.getTenantId()!=null) {
createUserResult = cognitoIdentityProvider.adminCreateUser(new AdminCreateUserRequest()
.withUserPoolId(tenantUserDto.getUserPoolId()).withUsername(user.getEmail())
.withUserAttributes(new AttributeType().withName("email").withValue(user.getEmail()),
new AttributeType().withName("email_verified").withValue("true"),
new AttributeType().withName("custom:tenant-id").withValue(tenantUserDto.getTenantId())));
} else {
createUserResult = cognitoIdentityProvider.adminCreateUser(new AdminCreateUserRequest()
.withUserPoolId(tenantUserDto.getUserPoolId()).withUsername(user.getEmail())
.withUserAttributes(new AttributeType().withName("email").withValue(user.getEmail()),
new AttributeType().withName("email_verified").withValue("true")));
}
UserType cognitoUser = createUserResult.getUser();
logger.info("Cognito - Create User Success=>" + cognitoUser.getUsername());
user.setCreated(cognitoUser.getUserCreateDate().toString());
user.setModified(cognitoUser.getUserLastModifiedDate().toString());
user.setEnabled(cognitoUser.getEnabled());
user.setStatus(cognitoUser.getUserStatus());
for (AttributeType userAttribute : cognitoUser.getAttributes()) {
switch (userAttribute.getName()) {
case "email":
user.setEmail(userAttribute.getValue());
break;
case "email_verified":
user.setVerified(userAttribute.getValue());
break;
}
}
return user;
}