1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 03:32:22 -05:00

LDAP: need to galLookup when search attribute is not in galfind result

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1341 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-08-16 10:27:08 +00:00
parent 0e0f2daae6
commit 1a328a5312
2 changed files with 14 additions and 8 deletions

View File

@ -198,13 +198,13 @@ public class DavExchangeSession extends ExchangeSession {
static final HashSet<String> GALLOOKUP_ATTRIBUTES = new HashSet<String>();
static {
GALLOOKUP_ATTRIBUTES.add("givenname");
GALLOOKUP_ATTRIBUTES.add("givenName");
GALLOOKUP_ATTRIBUTES.add("initials");
GALLOOKUP_ATTRIBUTES.add("sn");
GALLOOKUP_ATTRIBUTES.add("street");
GALLOOKUP_ATTRIBUTES.add("st");
GALLOOKUP_ATTRIBUTES.add("postalcode");
GALLOOKUP_ATTRIBUTES.add("c");
GALLOOKUP_ATTRIBUTES.add("co");
GALLOOKUP_ATTRIBUTES.add("departement");
GALLOOKUP_ATTRIBUTES.add("mobile");
}
@ -242,7 +242,8 @@ public class DavExchangeSession extends ExchangeSession {
if (condition instanceof MultiCondition) {
// TODO
} else if (condition instanceof AttributeCondition) {
String searchAttribute = GALFIND_CRITERIA_MAP.get(((ExchangeSession.AttributeCondition) condition).getAttributeName());
String searchAttributeName = ((ExchangeSession.AttributeCondition) condition).getAttributeName();
String searchAttribute = GALFIND_CRITERIA_MAP.get(searchAttributeName);
if (searchAttribute != null) {
String searchValue = ((ExchangeSession.AttributeCondition) condition).getValue();
Map<String, Map<String, String>> results;
@ -259,7 +260,7 @@ public class DavExchangeSession extends ExchangeSession {
contact.setName(result.get("AN"));
contact.put("imapUid", result.get("AN"));
buildGalfindContact(contact, result);
if (needGalLookup(returningAttributes)) {
if (needGalLookup(searchAttributeName, returningAttributes)) {
galLookup(contact);
}
if (condition.isMatch(contact)) {
@ -272,10 +273,13 @@ public class DavExchangeSession extends ExchangeSession {
return contacts;
}
protected boolean needGalLookup(Set<String> returningAttributes) {
// iCal search, do not call gallookup
if (returningAttributes == null) {
protected boolean needGalLookup(String searchAttributeName, Set<String> returningAttributes) {
// search attribute is gallookup attribute, need to fetch value for isMatch
if (GALLOOKUP_ATTRIBUTES.contains(searchAttributeName)) {
return true;
} else if (returningAttributes == null) {
return false;
// iCal search, do not call gallookup
} else if (returningAttributes.contains("apple-serviceslocator")) {
return false;
// return all attributes => call gallookup
@ -301,6 +305,7 @@ public class DavExchangeSession extends ExchangeSession {
*/
public void galLookup(Contact contact) {
if (!disableGalLookup) {
LOGGER.debug("galLookup("+contact.get("smtpemail1")+ ')');
GetMethod getMethod = null;
try {
getMethod = new GetMethod(URIUtil.encodePathQuery(getCmdBasePath() + "?Cmd=gallookup&ADDR=" + contact.get("smtpemail1")));

View File

@ -114,9 +114,10 @@ public class TestLdap extends AbstractExchangeSessionTestCase {
"(&(objectclass=inetOrgPerson)(objectclass=extensibleObject)(objectclass=apple-user)(|(|(uid=fair*)(cn=fair*))(givenname=fair*)(sn=fair*)(cn=fair*)(mail=fair*))(objectclass=posixAccount)(objectclass=shadowAccount))", searchControls);
}
public void testSearchByGivenName() throws NamingException {
public void testSearchByGivenNameWithoutReturningAttributes() throws NamingException {
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
searchControls.setReturningAttributes(new String[]{"uid"});
NamingEnumeration<SearchResult> searchResults = ldapContext.search("ou=people", "(givenName=mic*)", searchControls);
}