Index: contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMEntityDAO.java
===================================================================
--- contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMEntityDAO.java	(revision 1103)
+++ contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMEntityDAO.java	(revision 1545)
@@ -23,9 +23,14 @@
 import java.sql.ResultSet;
 import java.sql.Timestamp;
-import java.util.Enumeration;
-import java.util.Iterator;
+import java.util.Hashtable;
 import java.util.List;
 
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 import javax.sql.DataSource;
 
@@ -38,11 +43,4 @@
 import com.funambol.framework.tools.DBTools;
 import com.funambol.framework.tools.DataSourceTools;
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPAttributeSet;
-import com.novell.ldap.LDAPConnection;
-import com.novell.ldap.LDAPEntry;
-import com.novell.ldap.LDAPException;
-import com.novell.ldap.LDAPSearchResults;
-import com.novell.ldap.util.Base64;
 
 public abstract class PIMEntityDAO {
@@ -123,73 +121,105 @@
 	// -----------------------------------------------------------Public methods
 
+	@SuppressWarnings("unchecked")
 	protected String LdapUID(String server, String dc, String user)
 			throws Exception {
 
-		LDAPConnection ldap = new LDAPConnection();
-		String searchAttrs[] = { "uidNumber" };
-		String id_owner = null;
-
-		try {
-
-			ldap.connect(server, 389);
-			LDAPSearchResults searchResults = ldap.search(dc,
-					LDAPConnection.SCOPE_SUB, "(uid=" + user + ")",
-					searchAttrs, false);
-
-			while (searchResults.hasMore()) {
-
-				LDAPEntry nextEntry = null;
-				try {
-					nextEntry = searchResults.next();
-				} catch (LDAPException e) {
-					if (e.getResultCode() == LDAPException.LDAP_TIMEOUT
-							|| e.getResultCode() == LDAPException.CONNECT_ERROR)
-						break;
-					else
-						continue;
-				}
-				LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
-				Iterator allAttributes = attributeSet.iterator();
-
-				while (allAttributes.hasNext()) {
-
-					LDAPAttribute attribute = (LDAPAttribute) allAttributes
-							.next();
-					String attributeName = attribute.getName();
-					Enumeration allValues = attribute.getStringValues();
-
-					if (allValues != null) {
-
-						while (allValues.hasMoreElements()) {
-
-							String Value = (String) allValues.nextElement();
-
-							if (Base64.isLDIFSafe(Value)) {
-							} else {
-								Value = Base64.encode(Value.getBytes());
-							}
-
-							if (attributeName.equalsIgnoreCase("uidNumber")) {
-								id_owner = Value;
-								break;
-							}
-
-						}
-					}
-				}
-			}
-
-			ldap.disconnect();
-
-			if (id_owner == null) {
-				throw new LDAPException();
-			}
-
-		} catch (LDAPException e) {
-			log.info("Error while connecting and binding to LDAP: "
-					+ e.toString());
-		}
-
-		return id_owner;
+		String uidNumber=null;
+		
+		Hashtable env = new Hashtable();
+        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
+        env.put(Context.PROVIDER_URL, "ldap://" + server + ":" + 389);
+        
+        DirContext ctx = new InitialDirContext(env);
+        // Searching User
+        SearchControls ctls = new SearchControls();
+        ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+        ctls.setCountLimit(1);
+        ctls.setTimeLimit(10000); // Espera no max 10 segundos
+        String filter = "(uid=" + user + ")";
+        
+        NamingEnumeration answer = ctx.search(dc, filter, ctls);
+        if (answer.hasMore()) {
+            SearchResult sr = (SearchResult) answer.next();
+            try {
+                // Getting User attributes
+                uidNumber = sr.getAttributes().get("uidNumber").get(0).toString();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        ctx.close();
+		if (uidNumber == null) {
+			log.info("Error while connecting and binding to LDAP");
+		}
+
+		return uidNumber;
+
+            
+//		LDAPConnection ldap = new LDAPConnection();
+//		String searchAttrs[] = { "uidNumber" };
+//		String id_owner = null;
+//
+//		try {
+//
+//			ldap.connect(server, 389);
+//			LDAPSearchResults searchResults = ldap.search(dc,
+//					LDAPConnection.SCOPE_SUB, "(uid=" + user + ")",
+//					searchAttrs, false);
+//
+//			while (searchResults.hasMore()) {
+//
+//				LDAPEntry nextEntry = null;
+//				try {
+//					nextEntry = searchResults.next();
+//				} catch (LDAPException e) {
+//					if (e.getResultCode() == LDAPException.LDAP_TIMEOUT
+//							|| e.getResultCode() == LDAPException.CONNECT_ERROR)
+//						break;
+//					else
+//						continue;
+//				}
+//				LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
+//				Iterator allAttributes = attributeSet.iterator();
+//
+//				while (allAttributes.hasNext()) {
+//
+//					LDAPAttribute attribute = (LDAPAttribute) allAttributes
+//							.next();
+//					String attributeName = attribute.getName();
+//					Enumeration allValues = attribute.getStringValues();
+//
+//					if (allValues != null) {
+//
+//						while (allValues.hasMoreElements()) {
+//
+//							String Value = (String) allValues.nextElement();
+//
+//							if (Base64.isLDIFSafe(Value)) {
+//							} else {
+//								Value = Base64.encode(Value.getBytes());
+//							}
+//
+//							if (attributeName.equalsIgnoreCase("uidNumber")) {
+//								id_owner = Value;
+//								break;
+//							}
+//
+//						}
+//					}
+//				}
+//			}
+//
+//			ldap.disconnect();
+//
+//			if (id_owner == null) {
+//				throw new LDAPException();
+//			}
+//
+//		} catch (LDAPException e) {
+//			log.info("Error while connecting and binding to LDAP: "
+//					+ e.toString());
+//		}
+//		return id_owner;
 	}
 
