mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
LDAP: refactor contact find, generic attribute mapping
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@695 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
6ef071603a
commit
4e9e374ea1
@ -356,8 +356,8 @@ public class ExchangeSession {
|
|||||||
if (a_sUrlEndIndex >= 0 && a_sLgnEndIndex >= 0) {
|
if (a_sUrlEndIndex >= 0 && a_sLgnEndIndex >= 0) {
|
||||||
URI initmethodURI = initmethod.getURI();
|
URI initmethodURI = initmethod.getURI();
|
||||||
initmethodURI.setQuery(
|
initmethodURI.setQuery(
|
||||||
scriptValue.substring(a_sLgnIndex + 1, a_sLgnEndIndex) +
|
scriptValue.substring(a_sLgnIndex + 1, a_sLgnEndIndex) +
|
||||||
scriptValue.substring(a_sUrlIndex, a_sUrlEndIndex));
|
scriptValue.substring(a_sUrlIndex, a_sUrlEndIndex));
|
||||||
String src = initmethodURI.getURI();
|
String src = initmethodURI.getURI();
|
||||||
LOGGER.debug("Detected script based logon, redirect to form at " + src);
|
LOGGER.debug("Detected script based logon, redirect to form at " + src);
|
||||||
HttpMethod newInitMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, src);
|
HttpMethod newInitMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, src);
|
||||||
@ -2610,82 +2610,26 @@ public class ExchangeSession {
|
|||||||
Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
|
Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
|
||||||
Map<String, String> item;
|
Map<String, String> item;
|
||||||
for (MultiStatusResponse response : responses) {
|
for (MultiStatusResponse response : responses) {
|
||||||
DavPropertySet properties = response.getProperties(HttpStatus.SC_OK);
|
|
||||||
// TODO: improve mapping
|
|
||||||
String uid = getPropertyIfExists(properties, "uid", Namespace.getNamespace("DAV:"));
|
|
||||||
String email1 = getPropertyIfExists(properties, "email1", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
// patch email
|
|
||||||
if (email1 != null && email1.startsWith("\"")) {
|
|
||||||
int endIndex = email1.indexOf('\"', 1);
|
|
||||||
if (endIndex > 0) {
|
|
||||||
email1 = email1.substring(1, endIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String cn = getPropertyIfExists(properties, "cn", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String givenName = getPropertyIfExists(properties, "givenName", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String sn = getPropertyIfExists(properties, "sn", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String title = getPropertyIfExists(properties, "title", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String company = getPropertyIfExists(properties, "o", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String location = getPropertyIfExists(properties, "location", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String department = getPropertyIfExists(properties, "department", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
|
|
||||||
String telephoneNumber = getPropertyIfExists(properties, "telephoneNumber", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String initials = getPropertyIfExists(properties, "initials", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String street = getPropertyIfExists(properties, "street", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String st = getPropertyIfExists(properties, "st", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String postalcode = getPropertyIfExists(properties, "postalcode", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String c = getPropertyIfExists(properties, "c", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
String mobile = getPropertyIfExists(properties, "mobile", Namespace.getNamespace("urn:schemas:contacts:"));
|
|
||||||
item = new HashMap<String, String>();
|
item = new HashMap<String, String>();
|
||||||
if (uid != null) {
|
|
||||||
item.put("AN", uid);
|
DavPropertySet properties = response.getProperties(HttpStatus.SC_OK);
|
||||||
|
DavPropertyIterator propertiesIterator = properties.iterator();
|
||||||
|
while (propertiesIterator.hasNext()) {
|
||||||
|
DavProperty property = propertiesIterator.nextProperty();
|
||||||
|
String propertyName = property.getName().getName();
|
||||||
|
String propertyValue = (String) property.getValue();
|
||||||
|
if ("email1".equals(propertyName)) {
|
||||||
|
propertyName = "mail";
|
||||||
|
if (propertyValue != null && propertyValue.startsWith("\"")) {
|
||||||
|
int endIndex = propertyValue.indexOf('\"', 1);
|
||||||
|
if (endIndex > 0) {
|
||||||
|
propertyValue = propertyValue.substring(1, endIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.put(propertyName, propertyValue);
|
||||||
}
|
}
|
||||||
if (email1 != null) {
|
results.put(item.get("uid"), item);
|
||||||
item.put("EM", email1);
|
|
||||||
}
|
|
||||||
if (cn != null) {
|
|
||||||
item.put("DN", cn);
|
|
||||||
}
|
|
||||||
if (givenName != null) {
|
|
||||||
item.put("first", givenName);
|
|
||||||
}
|
|
||||||
if (sn != null) {
|
|
||||||
item.put("last", sn);
|
|
||||||
}
|
|
||||||
if (title != null) {
|
|
||||||
item.put("TL", title);
|
|
||||||
}
|
|
||||||
if (company != null) {
|
|
||||||
item.put("CP", company);
|
|
||||||
}
|
|
||||||
if (location != null) {
|
|
||||||
item.put("OFFICE", location);
|
|
||||||
}
|
|
||||||
if (department != null) {
|
|
||||||
item.put("department", department);
|
|
||||||
}
|
|
||||||
if (telephoneNumber != null) {
|
|
||||||
item.put("PH", telephoneNumber);
|
|
||||||
}
|
|
||||||
if (initials != null) {
|
|
||||||
item.put("initials", initials);
|
|
||||||
}
|
|
||||||
if (street != null) {
|
|
||||||
item.put("street", street);
|
|
||||||
}
|
|
||||||
if (st != null) {
|
|
||||||
item.put("state", st);
|
|
||||||
}
|
|
||||||
if (postalcode != null) {
|
|
||||||
item.put("zip", postalcode);
|
|
||||||
}
|
|
||||||
if (c != null) {
|
|
||||||
item.put("country", c);
|
|
||||||
}
|
|
||||||
if (mobile != null) {
|
|
||||||
item.put("mobile", mobile);
|
|
||||||
}
|
|
||||||
results.put(uid, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.debug("contactFind " + searchFilter + ": " + results.size() + " result(s)");
|
LOGGER.debug("contactFind " + searchFilter + ": " + results.size() + " result(s)");
|
||||||
|
@ -496,13 +496,19 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
if (session != null) {
|
if (session != null) {
|
||||||
// single user request
|
// single user request
|
||||||
String uid = dn.substring("uid=".length(), dn.indexOf(','));
|
String uid = dn.substring("uid=".length(), dn.indexOf(','));
|
||||||
Map<String, Map<String, String>> persons = session.galFind("AN", uid);
|
// first search in contact
|
||||||
Map<String, String> person = persons.get(uid.toLowerCase());
|
Map<String, Map<String, String>> persons = session.contactFind("\"DAV:uid\"='" + uid + '\'');
|
||||||
// filter out non exact results
|
// then in GAL
|
||||||
if (persons.size() > 1 || person == null) {
|
if (persons.isEmpty()) {
|
||||||
persons = new HashMap<String, Map<String, String>>();
|
persons = session.galFind("AN", uid);
|
||||||
if (person != null) {
|
|
||||||
persons.put(uid.toLowerCase(), person);
|
Map<String, String> person = persons.get(uid.toLowerCase());
|
||||||
|
// filter out non exact results
|
||||||
|
if (persons.size() > 1 || person == null) {
|
||||||
|
persons = new HashMap<String, Map<String, String>>();
|
||||||
|
if (person != null) {
|
||||||
|
persons.put(uid.toLowerCase(), person);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size = persons.size();
|
size = persons.size();
|
||||||
@ -713,23 +719,24 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.isEmpty();
|
boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.isEmpty();
|
||||||
boolean iCalSearch = returningAttributes.contains("apple-serviceslocator");
|
boolean iCalSearch = returningAttributes.contains("apple-serviceslocator");
|
||||||
boolean returnAllAttributes = returningAttributes.isEmpty();
|
boolean returnAllAttributes = returningAttributes.isEmpty();
|
||||||
for (Map<String, String> person : persons.values()) {
|
boolean needDetails = returnAllAttributes;
|
||||||
boolean needDetails = returnAllAttributes;
|
if (!needDetails) {
|
||||||
if (!needDetails) {
|
for (String attributeName : EXTENDED_ATTRIBUTES) {
|
||||||
for (String attributeName : EXTENDED_ATTRIBUTES) {
|
if (returningAttributes.contains(attributeName)) {
|
||||||
if (returningAttributes.contains(attributeName)) {
|
needDetails = true;
|
||||||
needDetails = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// iCal search, do not lookup details
|
}
|
||||||
if (iCalSearch) {
|
// iCal search, do not lookup details
|
||||||
needDetails = false;
|
if (iCalSearch) {
|
||||||
}
|
needDetails = false;
|
||||||
|
}
|
||||||
|
|
||||||
// add detailed information
|
for (Map<String, String> person : persons.values()) {
|
||||||
if (needDetails) {
|
|
||||||
|
// add detailed information, only for GAL entries
|
||||||
|
if (needDetails && person.get("AN") != null) {
|
||||||
session.galLookup(person);
|
session.galLookup(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -743,6 +750,10 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
String ldapAttribute = entry.getKey();
|
String ldapAttribute = entry.getKey();
|
||||||
String exchangeAttribute = entry.getValue();
|
String exchangeAttribute = entry.getValue();
|
||||||
String value = person.get(exchangeAttribute);
|
String value = person.get(exchangeAttribute);
|
||||||
|
// contactFind return ldap attributes directly
|
||||||
|
if (value == null) {
|
||||||
|
value = person.get(ldapAttribute);
|
||||||
|
}
|
||||||
if (value != null
|
if (value != null
|
||||||
&& (returnAllAttributes || returningAttributes.contains(ldapAttribute.toLowerCase()))) {
|
&& (returnAllAttributes || returningAttributes.contains(ldapAttribute.toLowerCase()))) {
|
||||||
ldapPerson.put(ldapAttribute, value);
|
ldapPerson.put(ldapAttribute, value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user