About UserManager sources


I’m trying to list users who have a specific role. I’d like to set the source as well, in case it would make the process shorter.

If I don’t specify any source, it works (but 5s quite long for such a simple query) :

import org.sonatype.nexus.security.SecuritySystem
import org.sonatype.nexus.security.user.UserManager
import org.sonatype.nexus.security.user.UserSearchCriteria

SecuritySystem ss = security.getSecuritySystem()

UserSearchCriteria criteria = new UserSearchCriteria()
users = ss.searchUsers(criteria)

size = users.size()

log.info("User count: $size")

for (user in users)
    log.info("User: $user")

In the result, I can see all the user source is set to “LDAP”.

So now I launch the task again with criteria.setSource('LDAP') and, surprise, there is no exception about not finding the userManager corresponding to “LDAP” source, but the user count is at “0”, what is happening here ? am I using the wrong string for source ? How can I get the “userManagers” map to iterate on keys and see what they are exactly ?

The LDAP manager does not page through users, it will retrieve the first X users that match the username search (in this case *) and check if any have matching roles. If the role is assigned via LDAP group, you should use the LDAP server for determining this information.