Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dewmini committed Nov 20, 2023
1 parent 554e719 commit b4cee1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion userdetails-cognito/grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ environments:
attributes:
affiliations:
enabled: true
attribute-name: 'custom:affiliation'
attribute-name: 'affiliation'

cognito:
mapping:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class Application extends GrailsAutoConfiguration {
}

@Bean('userService')
IUserService userService(TokenService tokenService, EmailService emailService, AWSCognitoIdentityProvider cognitoIdp, JwtProperties jwtProperties) {
IUserService userService(TokenService tokenService, EmailService emailService, AWSCognitoIdentityProvider cognitoIdp, JwtProperties jwtProperties,
LocationService locationService) {

CognitoUserService userService = new CognitoUserService()
userService.cognitoIdp = cognitoIdp
Expand All @@ -92,6 +93,7 @@ class Application extends GrailsAutoConfiguration {
userService.emailService = emailService
userService.tokenService = tokenService
userService.jwtProperties = jwtProperties
userService.locationService = locationService

userService.affiliationsEnabled = grailsApplication.config.getProperty('attributes.affiliations.enabled', Boolean, false)
userService.socialLoginGroups = grailsApplication.config.getProperty('users.delegated-group-names', List, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ class CognitoUserService implements IUserService<UserRecord, UserPropertyRecord,
token = results.getPaginationToken()

users.each {
def value = it.attributes.find { it.name == "custom.$s" }?.value
counts[value ?: ''] = ((counts[value ?: '']) ?: 0)++
def value = it.attributes.find {att -> att.name == "custom:$s" }?.value
counts[value ?: ''] = ((counts[value ?: '']) ?: 0) +1
}

results = token ? cognitoIdp.listUsers(new ListUsersRequest().withUserPoolId(poolId).withPaginationToken(token)) : null
Expand Down Expand Up @@ -733,8 +733,21 @@ class CognitoUserService implements IUserService<UserRecord, UserPropertyRecord,
propList.addAll(userRecord.userProperties.findAll { it.name == attribute })
}
else if(attribute){
//cannot implement this since cognito does not support custom attribute search
throw new NotImplementedException()
def token
def results = cognitoIdp.listUsers(new ListUsersRequest().withUserPoolId(poolId))

while (results) {
def users = results.getUsers()
token = results.getPaginationToken()

users.each {
def value = it.attributes.find {att -> att.name == "custom:$attribute" }?.value
if(value) {
propList.add(new UserPropertyRecord(user: cognitoUserTypeToUserRecord(it, false), name: attribute, value: value))
}
}
results = token ? cognitoIdp.listUsers(new ListUsersRequest().withUserPoolId(poolId).withPaginationToken(token)) : null
}
}
else{
//cannot implement this since cognito does not support custom attribute search
Expand Down

0 comments on commit b4cee1f

Please sign in to comment.