Skip to content

Instantly share code, notes, and snippets.

@neilherbertuk
Created December 16, 2022 21:05
Show Gist options
  • Save neilherbertuk/92e642cfac27af7af8e593ebb1c373ff to your computer and use it in GitHub Desktop.
Save neilherbertuk/92e642cfac27af7af8e593ebb1c373ff to your computer and use it in GitHub Desktop.
Find a single user by ID in OpenIAM
import java.util.List
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.openiam.common.beans.mq.UserRabbitMQService
import org.openiam.idm.srvc.user.dto.User
import org.openiam.idm.srvc.user.dto.UserCollection
import org.springframework.context.ApplicationContext
// Dependencies
Log log = LogFactory.getLog("findUserTest") // Logging
ApplicationContext appContext = (ApplicationContext) context // IoC Container
UserRabbitMQService userRabbitMQService = appContext.getBean(UserRabbitMQService.class) // Docs - https://download.openiam.com/release/enterprise/4.2.1.2/javadoc/org/openiam/common/beans/mq/UserRabbitMQService.html
log.info("Finding Scott Nelson by ID")
log.info("Performing search")
// Build a list of attributes you want returned for the user - Docs - https://download.openiam.com/release/enterprise/4.2.1.2/javadoc/org/openiam/idm/srvc/user/dto/UserCollection.html
List<UserCollection> userCollection = [UserCollection.PRINCIPALS, UserCollection.ATTRIBUTES, UserCollection.ORGANIZATIONS, UserCollection.EMAILS, UserCollection.SUPERVISORS]
User user = userRabbitMQService.getUser("3006", userCollection as UserCollection[])
if (user) {
log.info("${user.getId()} - First Name: ${user.getFirstName()}")
log.info("${user.getId()} - Last Name: ${user.getLastName()}")
log.info("${user}")
} else {
log.info("Could not find user")
}
output = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment