From 44c87d9c052d76ee8385ae414fc47d331f8fdbcf Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 26 Sep 2011 23:45:17 +0000 Subject: [PATCH] LDAP: fix DIGEST-MD5 SASL authentication for OSX Lion git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1798 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../exchange/ExchangeSessionFactory.java | 20 ++++++++++++------- src/java/davmail/ldap/LdapConnection.java | 5 +++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSessionFactory.java b/src/java/davmail/exchange/ExchangeSessionFactory.java index f884f1db..6edc32b6 100644 --- a/src/java/davmail/exchange/ExchangeSessionFactory.java +++ b/src/java/davmail/exchange/ExchangeSessionFactory.java @@ -96,6 +96,16 @@ public final class ExchangeSessionFactory { } } + private static String convertUserName(String userName) { + String result = userName; + // prepend default windows domain prefix + String defaultDomain = Settings.getProperty("davmail.defaultDomain"); + if (userName.indexOf('\\') < 0 && defaultDomain != null) { + result = defaultDomain + '\\' + userName; + } + return result; + } + /** * Create authenticated Exchange session * @@ -109,12 +119,7 @@ public final class ExchangeSessionFactory { ExchangeSession session = null; try { - // prepend default windows domain prefix - String defaultDomain = Settings.getProperty("davmail.defaultDomain"); - if (userName.indexOf('\\') < 0 && defaultDomain != null) { - userName = defaultDomain + '\\' + userName; - } - PoolKey poolKey = new PoolKey(baseUrl, userName, password); + PoolKey poolKey = new PoolKey(baseUrl, convertUserName(userName), password); synchronized (LOCK) { session = POOL_MAP.get(poolKey); @@ -263,8 +268,9 @@ public final class ExchangeSessionFactory { * @return user password */ public static String getUserPassword(String userName) { + String fullUserName = convertUserName(userName); for (PoolKey poolKey : POOL_MAP.keySet()) { - if (poolKey.userName.equals(userName)) { + if (poolKey.userName.equals(fullUserName)) { return poolKey.password; } } diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 42633418..0c914c05 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -510,7 +510,7 @@ public class LdapConnection extends AbstractConnection { protected static final byte[] EMPTY_BYTE_ARRAY= new byte[0]; protected void handleRequest(byte[] inbuf, int offset) throws IOException { - dumpBer(inbuf, offset); + //dumpBer(inbuf, offset); BerDecoder reqBer = new BerDecoder(inbuf, 0, offset); int currentMessageId = 0; try { @@ -575,7 +575,7 @@ public class LdapConnection extends AbstractConnection { } else { Map properties = new HashMap(); properties.put("javax.security.sasl.qop", "auth,auth-int"); - saslServer = Sasl.createSaslServer(mechanism, "ldap", InetAddress.getLocalHost().getHostName(), properties, callbackHandler); + saslServer = Sasl.createSaslServer(mechanism, "ldap", client.getLocalAddress().getHostAddress(), properties, callbackHandler); serverResponse = saslServer.evaluateResponse(EMPTY_BYTE_ARRAY); status = LDAP_SASL_BIND_IN_PROGRESS; } @@ -792,6 +792,7 @@ public class LdapConnection extends AbstractConnection { Map attributes = new HashMap(); attributes.put("objectClass", "top"); attributes.put("namingContexts", NAMING_CONTEXTS); + //attributes.put("supportedsaslmechanisms", "PLAIN"); sendEntry(currentMessageId, "Root DSE", attributes); }