1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-12 22:18:11 -05:00

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
This commit is contained in:
mguessan 2009-03-17 07:46:38 +00:00
parent e319712ce9
commit cf4a925b5a

View File

@ -26,8 +26,15 @@ public class LdapConnection extends AbstractConnection {
* Davmail base context * Davmail base context
*/ */
static final String BASE_CONTEXT = "ou=people"; static final String BASE_CONTEXT = "ou=people";
static final String BASE_CONTEXT_2 = "cn=users, ou=people"; static final String OD_BASE_CONTEXT = "o=od";
static final String COMPUTER_CONTEXT = "cn=computers, ou=people"; static final String OD_USER_CONTEXT = "cn=users, o=od";
static final String COMPUTER_CONTEXT = "cn=computers, o=od";
static final List<String> NAMING_CONTEXTS = new ArrayList<String>();
static {
NAMING_CONTEXTS.add(BASE_CONTEXT);
NAMING_CONTEXTS.add(OD_BASE_CONTEXT);
}
static final List<String> PERSON_OBJECT_CLASSES = new ArrayList<String>(); static final List<String> PERSON_OBJECT_CLASSES = new ArrayList<String>();
@ -36,6 +43,7 @@ public class LdapConnection extends AbstractConnection {
PERSON_OBJECT_CLASSES.add("person"); PERSON_OBJECT_CLASSES.add("person");
PERSON_OBJECT_CLASSES.add("organizationalPerson"); PERSON_OBJECT_CLASSES.add("organizationalPerson");
PERSON_OBJECT_CLASSES.add("inetOrgPerson"); PERSON_OBJECT_CLASSES.add("inetOrgPerson");
// OpenDirectory class for iCal
PERSON_OBJECT_CLASSES.add("apple-user"); PERSON_OBJECT_CLASSES.add("apple-user");
} }
@ -449,7 +457,7 @@ public class LdapConnection extends AbstractConnection {
} }
} }
size = persons.size(); size = persons.size();
sendPersons(currentMessageId, persons, returningAttributes); sendPersons(currentMessageId, dn.substring(dn.indexOf(',')), persons, returningAttributes);
} else { } else {
DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " unrecognized dn " + dn); DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " unrecognized dn " + dn);
} }
@ -457,7 +465,7 @@ public class LdapConnection extends AbstractConnection {
size = 1; size = 1;
// computer context for iCal // computer context for iCal
sendComputerContext(currentMessageId, returningAttributes); 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<String, Map<String, String>> persons = new HashMap<String, Map<String, String>>(); Map<String, Map<String, String>> persons = new HashMap<String, Map<String, String>>();
if (ldapFilter.isFullSearch()) { if (ldapFilter.isFullSearch()) {
// full search // full search
@ -496,7 +504,7 @@ public class LdapConnection extends AbstractConnection {
size = persons.size(); size = persons.size();
DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " found " + size + " results"); 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"); DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " end");
} else { } else {
DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " unrecognized dn " + dn); 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 * Convert to LDAP attributes and send entry
* *
* @param currentMessageId current Message Id * @param currentMessageId current Message Id
* @param baseContext request base context (BASE_CONTEXT or OD_BASE_CONTEXT)
* @param persons persons Map * @param persons persons Map
* @param returningAttributes returning attributes * @param returningAttributes returning attributes
* @throws IOException on error * @throws IOException on error
*/ */
protected void sendPersons(int currentMessageId, Map<String, Map<String, String>> persons, Set<String> returningAttributes) throws IOException { protected void sendPersons(int currentMessageId, String baseContext, Map<String, Map<String, String>> persons, Set<String> returningAttributes) throws IOException {
boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.size() == 0; boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.size() == 0;
boolean returnAllAttributes = returningAttributes.size() == 0; boolean returnAllAttributes = returningAttributes.size() == 0;
for (Map<String, String> person : persons.values()) { for (Map<String, String> person : persons.values()) {
@ -678,8 +687,8 @@ public class LdapConnection extends AbstractConnection {
if (needObjectClasses) { if (needObjectClasses) {
ldapPerson.put("objectClass", PERSON_OBJECT_CLASSES); ldapPerson.put("objectClass", PERSON_OBJECT_CLASSES);
} }
DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " send uid=" + ldapPerson.get("uid") + " " + ldapPerson); DavGatewayTray.debug("LDAP_REQ_SEARCH " + currentMessageId + " send uid=" + ldapPerson.get("uid") + baseContext + " " + ldapPerson);
sendEntry(currentMessageId, "uid=" + ldapPerson.get("uid") + "," + BASE_CONTEXT, ldapPerson); sendEntry(currentMessageId, "uid=" + ldapPerson.get("uid") + baseContext, ldapPerson);
} }
} }
@ -695,7 +704,7 @@ public class LdapConnection extends AbstractConnection {
Map<String, Object> attributes = new HashMap<String, Object>(); Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("objectClass", "top"); attributes.put("objectClass", "top");
attributes.put("namingContexts", BASE_CONTEXT); attributes.put("namingContexts", NAMING_CONTEXTS);
sendEntry(currentMessageId, "Root DSE", attributes); sendEntry(currentMessageId, "Root DSE", attributes);
} }