|
|
|
|
@ -54,7 +54,11 @@ public class LdapDirectoryImpl
|
|
|
|
|
/**
|
|
|
|
|
* Name of avatar attribute.
|
|
|
|
|
*/
|
|
|
|
|
private static final String PHOTO_ATTRIBUTE = "jpegPhoto";
|
|
|
|
|
private static final String[] PHOTO_ATTRIBUTES = new String[]
|
|
|
|
|
{
|
|
|
|
|
"jpegPhoto",
|
|
|
|
|
"thumbnailPhoto"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* data structure used to store the LDAP attributes that
|
|
|
|
|
@ -208,6 +212,12 @@ public LdapDirectoryImpl(LdapDirectorySettings settings)
|
|
|
|
|
{
|
|
|
|
|
searchableAttrs.add(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings.isPhotoInline())
|
|
|
|
|
{
|
|
|
|
|
retrievableAttributes.add("jpegPhoto");
|
|
|
|
|
retrievableAttributes.add("thumbnailPhoto");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -385,7 +395,7 @@ public void run()
|
|
|
|
|
|
|
|
|
|
SearchResult searchResult =
|
|
|
|
|
(SearchResult) results.next();
|
|
|
|
|
Map<String, Set<String>> retrievedAttributes =
|
|
|
|
|
Map<String, Set<Object>> retrievedAttributes =
|
|
|
|
|
retrieveAttributes(searchResult);
|
|
|
|
|
LdapPersonFound person =
|
|
|
|
|
buildPerson(
|
|
|
|
|
@ -411,7 +421,7 @@ public void run()
|
|
|
|
|
}
|
|
|
|
|
catch(OperationNotSupportedException e)
|
|
|
|
|
{
|
|
|
|
|
logger.trace(
|
|
|
|
|
logger.error(
|
|
|
|
|
"use bind DN without password during search" +
|
|
|
|
|
" for real query \"" +
|
|
|
|
|
realQueryString + "\" (initial query: \"" +
|
|
|
|
|
@ -425,7 +435,7 @@ public void run()
|
|
|
|
|
}
|
|
|
|
|
catch(AuthenticationException e)
|
|
|
|
|
{
|
|
|
|
|
logger.trace(
|
|
|
|
|
logger.error(
|
|
|
|
|
"authentication failed during search" +
|
|
|
|
|
" for real query \"" +
|
|
|
|
|
realQueryString + "\" (initial query: \"" +
|
|
|
|
|
@ -439,7 +449,7 @@ public void run()
|
|
|
|
|
}
|
|
|
|
|
catch(NamingException e)
|
|
|
|
|
{
|
|
|
|
|
logger.trace(
|
|
|
|
|
logger.error(
|
|
|
|
|
"an external exception was thrown during search" +
|
|
|
|
|
" for real query \"" +
|
|
|
|
|
realQueryString + "\" (initial query: \"" +
|
|
|
|
|
@ -469,6 +479,19 @@ public void run()
|
|
|
|
|
// whether sleep was interrupted
|
|
|
|
|
// is not that important
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.error("search for real query \"" + realQueryString +
|
|
|
|
|
"\" (initial query: \"" + query.toString() +
|
|
|
|
|
"\") on " + LdapDirectoryImpl.this +
|
|
|
|
|
" cancelled at state " + cancelState, e);
|
|
|
|
|
|
|
|
|
|
endEvent = new LdapEvent(
|
|
|
|
|
LdapDirectoryImpl.this,
|
|
|
|
|
LdapEvent.LdapEventCause.SEARCH_ERROR,
|
|
|
|
|
query
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
fireLdapEvent(endEvent, caller);
|
|
|
|
|
@ -504,9 +527,14 @@ private void checkCancel()
|
|
|
|
|
searchThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String[]
|
|
|
|
|
private String[]
|
|
|
|
|
buildIntermediateQueryStrings(String initialQueryString)
|
|
|
|
|
{
|
|
|
|
|
if (!this.settings.isMangleQuery())
|
|
|
|
|
{
|
|
|
|
|
return new String[] { initialQueryString };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// search for "doe john" as well "as john doe"
|
|
|
|
|
String[] words = initialQueryString.split(" ");
|
|
|
|
|
String[] intermediateQueryStrings;
|
|
|
|
|
@ -534,28 +562,27 @@ private void checkCancel()
|
|
|
|
|
* @param searchResult the results to browse for attributes
|
|
|
|
|
* @return the attributes in a Map
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Set<String>>
|
|
|
|
|
private Map<String, Set<Object>>
|
|
|
|
|
retrieveAttributes(SearchResult searchResult)
|
|
|
|
|
throws NamingException
|
|
|
|
|
{
|
|
|
|
|
Attributes attributes =
|
|
|
|
|
searchResult.getAttributes();
|
|
|
|
|
Map<String, Set<String>> retrievedAttributes =
|
|
|
|
|
new HashMap<String, Set<String>>();
|
|
|
|
|
Map<String, Set<Object>> retrievedAttributes =
|
|
|
|
|
new HashMap<String, Set<Object>>();
|
|
|
|
|
NamingEnumeration<String> ids = attributes.getIDs();
|
|
|
|
|
while(ids.hasMore())
|
|
|
|
|
{
|
|
|
|
|
String id = ids.next();
|
|
|
|
|
if(retrievableAttributes.contains(id) || containsAttribute(id))
|
|
|
|
|
{
|
|
|
|
|
Set<String> valuesSet = new HashSet<String>();
|
|
|
|
|
Set<Object> valuesSet = new HashSet<Object>();
|
|
|
|
|
retrievedAttributes.put(id, valuesSet);
|
|
|
|
|
Attribute attribute = attributes.get(id);
|
|
|
|
|
NamingEnumeration<?> values = attribute.getAll();
|
|
|
|
|
while(values.hasMore())
|
|
|
|
|
{
|
|
|
|
|
String value = (String) values.next();
|
|
|
|
|
valuesSet.add(value);
|
|
|
|
|
valuesSet.add(values.next());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -574,7 +601,7 @@ private void checkCancel()
|
|
|
|
|
LdapQuery query,
|
|
|
|
|
String dn,
|
|
|
|
|
Map<String,
|
|
|
|
|
Set<String>> retrievedAttributes
|
|
|
|
|
Set<Object>> retrievedAttributes
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
LdapPersonFound person =
|
|
|
|
|
@ -584,19 +611,22 @@ private void checkCancel()
|
|
|
|
|
if(retrievedAttributes.get("givenname") != null)
|
|
|
|
|
{
|
|
|
|
|
String firstName =
|
|
|
|
|
retrievedAttributes.get("givenname").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("givenname")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setFirstName(firstName);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("givenName") != null)
|
|
|
|
|
{
|
|
|
|
|
String firstName =
|
|
|
|
|
retrievedAttributes.get("givenName").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("givenName")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setFirstName(firstName);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("gn") != null)
|
|
|
|
|
{
|
|
|
|
|
String firstName =
|
|
|
|
|
retrievedAttributes.get("gn").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("gn")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setFirstName(firstName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -604,13 +634,15 @@ else if(retrievedAttributes.get("gn") != null)
|
|
|
|
|
if(retrievedAttributes.get("sn") != null)
|
|
|
|
|
{
|
|
|
|
|
String surname =
|
|
|
|
|
retrievedAttributes.get("sn").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("sn")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setSurname(surname);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("surname") != null)
|
|
|
|
|
{
|
|
|
|
|
String surname =
|
|
|
|
|
retrievedAttributes.get("surname").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("surname")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setSurname(surname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -618,19 +650,22 @@ else if(retrievedAttributes.get("surname") != null)
|
|
|
|
|
if(retrievedAttributes.get("displayName") != null)
|
|
|
|
|
{
|
|
|
|
|
String displayName =
|
|
|
|
|
retrievedAttributes.get("displayName").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("displayName")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDisplayName(displayName);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("cn") != null)
|
|
|
|
|
{
|
|
|
|
|
String displayName =
|
|
|
|
|
retrievedAttributes.get("cn").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("cn")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDisplayName(displayName);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("commonname") != null)
|
|
|
|
|
{
|
|
|
|
|
String displayName =
|
|
|
|
|
retrievedAttributes.get("commonname").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("commonname")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDisplayName(displayName);
|
|
|
|
|
}
|
|
|
|
|
if(person.getDisplayName() == null)
|
|
|
|
|
@ -648,20 +683,21 @@ else if(retrievedAttributes.get("commonname") != null)
|
|
|
|
|
if(retrievedAttributes.get("o") != null)
|
|
|
|
|
{
|
|
|
|
|
String organization =
|
|
|
|
|
retrievedAttributes.get("o").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("o").iterator().next();
|
|
|
|
|
person.setOrganization(organization);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("organizationName") != null)
|
|
|
|
|
{
|
|
|
|
|
String organization =
|
|
|
|
|
retrievedAttributes.get("organizationName").iterator()
|
|
|
|
|
.next();
|
|
|
|
|
(String) retrievedAttributes.get("organizationName")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setOrganization(organization);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("company") != null)
|
|
|
|
|
{
|
|
|
|
|
String organization =
|
|
|
|
|
retrievedAttributes.get("company").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("company")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setOrganization(organization);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -669,42 +705,60 @@ else if(retrievedAttributes.get("company") != null)
|
|
|
|
|
if(retrievedAttributes.get("company") != null)
|
|
|
|
|
{
|
|
|
|
|
String department =
|
|
|
|
|
retrievedAttributes.get("company").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("company")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDepartment(department);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("ou") != null)
|
|
|
|
|
{
|
|
|
|
|
String department =
|
|
|
|
|
retrievedAttributes.get("ou").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("ou").iterator().next();
|
|
|
|
|
person.setDepartment(department);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("orgunit") != null)
|
|
|
|
|
{
|
|
|
|
|
String department =
|
|
|
|
|
retrievedAttributes.get("orgunit").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("orgunit")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDepartment(department);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("organizationalUnitName") != null)
|
|
|
|
|
{
|
|
|
|
|
String department =
|
|
|
|
|
retrievedAttributes.get("organizationalUnitName").
|
|
|
|
|
(String) retrievedAttributes.get("organizationalUnitName").
|
|
|
|
|
iterator().next();
|
|
|
|
|
person.setDepartment(department);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("department") != null)
|
|
|
|
|
{
|
|
|
|
|
String department =
|
|
|
|
|
retrievedAttributes.get("department").iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get("department")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDepartment(department);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("departmentNumber") != null)
|
|
|
|
|
{
|
|
|
|
|
String department =
|
|
|
|
|
retrievedAttributes.get("departmentNumber").iterator().
|
|
|
|
|
next();
|
|
|
|
|
(String) retrievedAttributes.get("departmentNumber")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setDepartment(department);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(retrievedAttributes.get("jpegPhoto") != null)
|
|
|
|
|
{
|
|
|
|
|
byte[] photo =
|
|
|
|
|
(byte[])retrievedAttributes.get("jpegPhoto")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setPhoto(photo);
|
|
|
|
|
}
|
|
|
|
|
else if(retrievedAttributes.get("thumbnailPhoto") != null)
|
|
|
|
|
{
|
|
|
|
|
byte[] photo =
|
|
|
|
|
(byte[])retrievedAttributes.get("thumbnailPhoto")
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.setPhoto(photo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mail
|
|
|
|
|
List<String> attrs = attributesMap.get("mail");
|
|
|
|
|
|
|
|
|
|
@ -712,8 +766,9 @@ else if(retrievedAttributes.get("departmentNumber") != null)
|
|
|
|
|
{
|
|
|
|
|
if(retrievedAttributes.get(attr) != null)
|
|
|
|
|
{
|
|
|
|
|
for(String mail : retrievedAttributes.get(attr))
|
|
|
|
|
for(Object o : retrievedAttributes.get(attr))
|
|
|
|
|
{
|
|
|
|
|
String mail = o.toString();
|
|
|
|
|
if(!mail.contains("@"))
|
|
|
|
|
{
|
|
|
|
|
if(settings.getMailSuffix() != null)
|
|
|
|
|
@ -736,7 +791,8 @@ else if(retrievedAttributes.get("departmentNumber") != null)
|
|
|
|
|
if(retrievedAttributes.get(attr) != null)
|
|
|
|
|
{
|
|
|
|
|
String phone =
|
|
|
|
|
retrievedAttributes.get(attr).iterator().next();
|
|
|
|
|
(String) retrievedAttributes.get(attr)
|
|
|
|
|
.iterator().next();
|
|
|
|
|
person.addWorkPhone(phone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -748,9 +804,9 @@ else if(retrievedAttributes.get("departmentNumber") != null)
|
|
|
|
|
{
|
|
|
|
|
if(retrievedAttributes.get(attr) != null)
|
|
|
|
|
{
|
|
|
|
|
for(String phone : retrievedAttributes.get(attr))
|
|
|
|
|
for(Object phone : retrievedAttributes.get(attr))
|
|
|
|
|
{
|
|
|
|
|
person.addMobilePhone(phone);
|
|
|
|
|
person.addMobilePhone(phone.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -762,9 +818,9 @@ else if(retrievedAttributes.get("departmentNumber") != null)
|
|
|
|
|
{
|
|
|
|
|
if(retrievedAttributes.get(attr) != null)
|
|
|
|
|
{
|
|
|
|
|
for(String phone : retrievedAttributes.get(attr))
|
|
|
|
|
for(Object phone : retrievedAttributes.get(attr))
|
|
|
|
|
{
|
|
|
|
|
person.addHomePhone(phone);
|
|
|
|
|
person.addHomePhone(phone.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -836,27 +892,21 @@ private boolean textHasContent(String aText)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Builds an LDAP search filter, base on the query string entered
|
|
|
|
|
* e.g. (&(|(mail=*)(telephoneNumber=*))(|(cn=*query*)(sn=*query*)(givenname=*query*)))
|
|
|
|
|
* Builds an LDAP search filter, based on the query string entered and the
|
|
|
|
|
* searchable fields defined in the static constructor. If a custom query is
|
|
|
|
|
* defined this is used instead. e.g.
|
|
|
|
|
* (|(|(mail=query)(telephoneNumber=query)))
|
|
|
|
|
*
|
|
|
|
|
* @return an LDAP search filter
|
|
|
|
|
*/
|
|
|
|
|
private String buildSearchFilter(String query)
|
|
|
|
|
{
|
|
|
|
|
StringBuffer searchFilter = new StringBuffer();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
searchFilter.append("(&(|");
|
|
|
|
|
|
|
|
|
|
for(String attribute : retrievableAttributes)
|
|
|
|
|
if ("custom".equals(settings.getQueryMode()))
|
|
|
|
|
{
|
|
|
|
|
searchFilter.append("(");
|
|
|
|
|
searchFilter.append(attribute);
|
|
|
|
|
searchFilter.append("=*)");
|
|
|
|
|
return settings.getCustomQuery().replace("<query>", query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchFilter.append(")(|");
|
|
|
|
|
*/
|
|
|
|
|
StringBuffer searchFilter = new StringBuffer();
|
|
|
|
|
searchFilter.append("(|");
|
|
|
|
|
|
|
|
|
|
/* cn=*query* OR sn=*query* OR ... */
|
|
|
|
|
@ -966,6 +1016,11 @@ public Collection<String> searchChildren(final String dn)
|
|
|
|
|
*/
|
|
|
|
|
byte[] fetchPhotoForPerson(String dn)
|
|
|
|
|
{
|
|
|
|
|
if (this.settings.isPhotoInline())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] photo = null;
|
|
|
|
|
InitialDirContext dirContext = null;
|
|
|
|
|
|
|
|
|
|
@ -973,8 +1028,7 @@ byte[] fetchPhotoForPerson(String dn)
|
|
|
|
|
|
|
|
|
|
final SearchControls searchCtl = new SearchControls();
|
|
|
|
|
searchCtl.setSearchScope(SearchControls.OBJECT_SCOPE);
|
|
|
|
|
String[] returningAttributes = { PHOTO_ATTRIBUTE };
|
|
|
|
|
searchCtl.setReturningAttributes(returningAttributes);
|
|
|
|
|
searchCtl.setReturningAttributes(PHOTO_ATTRIBUTES);
|
|
|
|
|
|
|
|
|
|
logger.trace("starting photo retrieval...");
|
|
|
|
|
try
|
|
|
|
|
@ -991,13 +1045,16 @@ byte[] fetchPhotoForPerson(String dn)
|
|
|
|
|
{
|
|
|
|
|
SearchResult searchResult = (SearchResult) result.next();
|
|
|
|
|
Attributes attributes = searchResult.getAttributes();
|
|
|
|
|
Attribute attribute = attributes.get(PHOTO_ATTRIBUTE);
|
|
|
|
|
if(attribute != null)
|
|
|
|
|
for (String a : PHOTO_ATTRIBUTES)
|
|
|
|
|
{
|
|
|
|
|
NamingEnumeration<?> values = attribute.getAll();
|
|
|
|
|
if(values.hasMore())
|
|
|
|
|
Attribute attribute = attributes.get(a);
|
|
|
|
|
if(attribute != null)
|
|
|
|
|
{
|
|
|
|
|
photo = (byte[]) values.next();
|
|
|
|
|
NamingEnumeration<?> values = attribute.getAll();
|
|
|
|
|
if(values.hasMore())
|
|
|
|
|
{
|
|
|
|
|
photo = (byte[]) values.next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|