Details
-
Bug
-
Resolution: Fixed
-
Minor
-
2.5.35
-
None
Description
2020-10-09 05:21:30,423: [DefaultQuartzScheduler_Worker-8] ERROR GrouperLoaderJob.runJobLdap(663) - Error on job: LDAP_GROUPS_FROM_ATTRIBUTES__etc:loader:hr:dept:staffLoader__0d57ed2259df4234a3c3f950c310d7f1
|
java.lang.RuntimeException: java.util.NoSuchElementException: Error querying ldap server id: UncLdap, searchDn: ou=People,dc=unc,dc=edu, filter: '(&(objectclass=uncjob)(owner=*)(departmentNumber=*)(!(uncjobfunction=faculty)))', returning subject attribute: owner
|
at edu.internet2.middleware.grouper.app.loader.db.GrouperLoaderResultset.getLdapMembershipsForLdapGroupsFromAttributes(GrouperLoaderResultset.java:1269)
|
at edu.internet2.middleware.grouper.app.loader.db.GrouperLoaderResultset.initForLdapGroupsFromAttributes(GrouperLoaderResultset.java:912)
|
at edu.internet2.middleware.grouper.app.loader.GrouperLoaderType$11.runJob(GrouperLoaderType.java:1154)
|
at edu.internet2.middleware.grouper.app.loader.GrouperLoaderJob.runJobLdap(GrouperLoaderJob.java:643)
|
at edu.internet2.middleware.grouper.app.loader.GrouperLoaderJob.execute(GrouperLoaderJob.java:337)
|
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
|
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
|
Caused by: java.util.NoSuchElementException: Error querying ldap server id: UncLdap, searchDn: ou=People,dc=unc,dc=edu, filter: '(&(objectclass=uncjob)(owner=*)(departmentNumber=*)(!(uncjobfunction=faculty)))', returning subject attribute: owner
|
at java.util.ArrayList$Itr.next(ArrayList.java:864)
|
at edu.internet2.middleware.grouper.app.loader.db.GrouperLoaderResultset.getLdapMembershipsForLdapGroupsFromAttributes(GrouperLoaderResultset.java:1085)
|
... 6 more
|
The problem is in conditional logic like
LdapAttribute groupAttribute = searchResult.getAttribute(groupAttributeName)
|
if (groupAttribute != null) {
|
String attributeValue = groupAttribute.getStringValues().iterator().next()
|
}
|
The getAttribute(attr) call does no return null if the attribute isn't found; it results an empty list. So the `groupAttribute != null` check is ineffective. But calling iterator() on an empty list returns null (wtf?), which gives an NPE when calling next().
Easily fixed by an additional check for an empty list:
if (groupAttribute != null && !groupAttribute.getStringValues().isEmpty()) {
|
The side effect of this is that any EL using the attribute will return "null" as the attribute value. But using the ?: operator does work as a fallback to a default; e.g.:
displayName EL = "Base:HR:Dept:${groupAttributes['ou']?:'?missing ou?'} (${groupAttribute}):${groupAttributes['ou']?:'?missing ou?'} -Staff"
|
result: Base:HR:Dept:?missing ou? (990092):?missing ou? -Staff