From cf4a925b5a4e0b2d5ee3efe9a9eb099743c445da Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 17 Mar 2009 07:46:38 +0000 Subject: [PATCH] LDAP: iCal autocomplete, moved to separate o=od naming context git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@447 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/ldap/LdapConnection.java | 37 ++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 1f4f91c4..214df4f3 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -26,8 +26,15 @@ public class LdapConnection extends AbstractConnection { * Davmail base context */ static final String BASE_CONTEXT = "ou=people"; - static final String BASE_CONTEXT_2 = "cn=users, ou=people"; - static final String COMPUTER_CONTEXT = "cn=computers, ou=people"; + static final String OD_BASE_CONTEXT = "o=od"; + static final String OD_USER_CONTEXT = "cn=users, o=od"; + static final String COMPUTER_CONTEXT = "cn=computers, o=od"; + + static final List NAMING_CONTEXTS = new ArrayList(); + static { + NAMING_CONTEXTS.add(BASE_CONTEXT); + NAMING_CONTEXTS.add(OD_BASE_CONTEXT); + } static final List PERSON_OBJECT_CLASSES = new ArrayList(); @@ -36,6 +43,7 @@ public class LdapConnection extends AbstractConnection { PERSON_OBJECT_CLASSES.add("person"); PERSON_OBJECT_CLASSES.add("organizationalPerson"); PERSON_OBJECT_CLASSES.add("inetOrgPerson"); + // OpenDirectory class for iCal PERSON_OBJECT_CLASSES.add("apple-user"); } @@ -82,7 +90,7 @@ public class LdapConnection extends AbstractConnection { "" + "com.apple.macosxserver.virtualhosts" + "" + - ""+VIRTUALHOST_GUID+"" + + "" + VIRTUALHOST_GUID + "" + "" + "hostDetails" + "" + @@ -132,7 +140,7 @@ public class LdapConnection extends AbstractConnection { ""; static { - STATIC_ATTRIBUTE_MAP.put("apple-serviceslocator", COMPUTER_GUID+":"+VIRTUALHOST_GUID+":calendar"); + STATIC_ATTRIBUTE_MAP.put("apple-serviceslocator", COMPUTER_GUID + ":" + VIRTUALHOST_GUID + ":calendar"); } static final HashSet EXTENDED_ATTRIBUTES = new HashSet(); @@ -449,7 +457,7 @@ public class LdapConnection extends AbstractConnection { } } size = persons.size(); - sendPersons(currentMessageId, persons, returningAttributes); + sendPersons(currentMessageId, dn.substring(dn.indexOf(',')), persons, returningAttributes); } else { DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " unrecognized dn " + dn); } @@ -457,7 +465,7 @@ public class LdapConnection extends AbstractConnection { size = 1; // computer context for iCal sendComputerContext(currentMessageId, returningAttributes); - } else if ((BASE_CONTEXT.equalsIgnoreCase(dn) || BASE_CONTEXT_2.equalsIgnoreCase(dn)) && (session != null)) { + } else if ((BASE_CONTEXT.equalsIgnoreCase(dn) || OD_USER_CONTEXT.equalsIgnoreCase(dn)) && (session != null)) { Map> persons = new HashMap>(); if (ldapFilter.isFullSearch()) { // full search @@ -496,7 +504,7 @@ public class LdapConnection extends AbstractConnection { size = persons.size(); DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " found " + size + " results"); - sendPersons(currentMessageId, persons, returningAttributes); + sendPersons(currentMessageId, ", "+dn, persons, returningAttributes); DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " end"); } else { DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " unrecognized dn " + dn); @@ -625,11 +633,12 @@ public class LdapConnection extends AbstractConnection { * Convert to LDAP attributes and send entry * * @param currentMessageId current Message Id + * @param baseContext request base context (BASE_CONTEXT or OD_BASE_CONTEXT) * @param persons persons Map * @param returningAttributes returning attributes * @throws IOException on error */ - protected void sendPersons(int currentMessageId, Map> persons, Set returningAttributes) throws IOException { + protected void sendPersons(int currentMessageId, String baseContext, Map> persons, Set returningAttributes) throws IOException { boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.size() == 0; boolean returnAllAttributes = returningAttributes.size() == 0; for (Map person : persons.values()) { @@ -678,8 +687,8 @@ public class LdapConnection extends AbstractConnection { if (needObjectClasses) { ldapPerson.put("objectClass", PERSON_OBJECT_CLASSES); } - DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " send uid=" + ldapPerson.get("uid") + " " + ldapPerson); - sendEntry(currentMessageId, "uid=" + ldapPerson.get("uid") + "," + BASE_CONTEXT, ldapPerson); + DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " send uid=" + ldapPerson.get("uid") + baseContext + " " + ldapPerson); + sendEntry(currentMessageId, "uid=" + ldapPerson.get("uid") + baseContext, ldapPerson); } } @@ -695,7 +704,7 @@ public class LdapConnection extends AbstractConnection { Map attributes = new HashMap(); attributes.put("objectClass", "top"); - attributes.put("namingContexts", BASE_CONTEXT); + attributes.put("namingContexts", NAMING_CONTEXTS); sendEntry(currentMessageId, "Root DSE", attributes); } @@ -713,7 +722,7 @@ public class LdapConnection extends AbstractConnection { DavGatewayTray.debug("Couldn't get hostname"); } - // If we can't get the hostname, just return localhost. + // If we can't get the hostname, just return localhost. return "localhost"; } @@ -739,8 +748,8 @@ public class LdapConnection extends AbstractConnection { addIf(attributes, returningAttributes, "apple-serviceslocator", "::anyService"); addIf(attributes, returningAttributes, "cn", hostName()); - String dn = "cn=" + hostName() + ", " + COMPUTER_CONTEXT; - DavGatewayTray.debug("Sending computer context " + dn); + String dn = "cn=" + hostName() + ", " + COMPUTER_CONTEXT; + DavGatewayTray.debug("Sending computer context " + dn); sendEntry(currentMessageId, dn, attributes); }