Skip to content

Commit b4cee1f

Browse files
committed
Fix issues
1 parent 554e719 commit b4cee1f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

userdetails-cognito/grails-app/conf/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ environments:
187187
attributes:
188188
affiliations:
189189
enabled: true
190-
attribute-name: 'custom:affiliation'
190+
attribute-name: 'affiliation'
191191

192192
cognito:
193193
mapping:

userdetails-cognito/grails-app/init/au/org/ala/userdetails/cognito/Application.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class Application extends GrailsAutoConfiguration {
8383
}
8484

8585
@Bean('userService')
86-
IUserService userService(TokenService tokenService, EmailService emailService, AWSCognitoIdentityProvider cognitoIdp, JwtProperties jwtProperties) {
86+
IUserService userService(TokenService tokenService, EmailService emailService, AWSCognitoIdentityProvider cognitoIdp, JwtProperties jwtProperties,
87+
LocationService locationService) {
8788

8889
CognitoUserService userService = new CognitoUserService()
8990
userService.cognitoIdp = cognitoIdp
@@ -92,6 +93,7 @@ class Application extends GrailsAutoConfiguration {
9293
userService.emailService = emailService
9394
userService.tokenService = tokenService
9495
userService.jwtProperties = jwtProperties
96+
userService.locationService = locationService
9597

9698
userService.affiliationsEnabled = grailsApplication.config.getProperty('attributes.affiliations.enabled', Boolean, false)
9799
userService.socialLoginGroups = grailsApplication.config.getProperty('users.delegated-group-names', List, [])

userdetails-cognito/src/main/groovy/au/org/ala/userdetails/CognitoUserService.groovy

+17-4
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ class CognitoUserService implements IUserService<UserRecord, UserPropertyRecord,
472472
token = results.getPaginationToken()
473473

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

479479
results = token ? cognitoIdp.listUsers(new ListUsersRequest().withUserPoolId(poolId).withPaginationToken(token)) : null
@@ -733,8 +733,21 @@ class CognitoUserService implements IUserService<UserRecord, UserPropertyRecord,
733733
propList.addAll(userRecord.userProperties.findAll { it.name == attribute })
734734
}
735735
else if(attribute){
736-
//cannot implement this since cognito does not support custom attribute search
737-
throw new NotImplementedException()
736+
def token
737+
def results = cognitoIdp.listUsers(new ListUsersRequest().withUserPoolId(poolId))
738+
739+
while (results) {
740+
def users = results.getUsers()
741+
token = results.getPaginationToken()
742+
743+
users.each {
744+
def value = it.attributes.find {att -> att.name == "custom:$attribute" }?.value
745+
if(value) {
746+
propList.add(new UserPropertyRecord(user: cognitoUserTypeToUserRecord(it, false), name: attribute, value: value))
747+
}
748+
}
749+
results = token ? cognitoIdp.listUsers(new ListUsersRequest().withUserPoolId(poolId).withPaginationToken(token)) : null
750+
}
738751
}
739752
else{
740753
//cannot implement this since cognito does not support custom attribute search

0 commit comments

Comments
 (0)