// Path: src/main/java/com/asolutions/scmsshd/ldap/LDAPBindingProvider.java
// public class LDAPBindingProvider {
// 	private String lookupUserDN;
// 	private String lookupUserPassword;
// 	private String url;
// 	private boolean promiscuous;
// 	
// 	public LDAPBindingProvider(String lookupUserDN, String lookupUserPassword,
// 			String url, boolean promiscuous) {
// 		this.lookupUserDN = lookupUserDN;
// 		this.lookupUserPassword = lookupUserPassword;
// 		this.url = url;
// 		this.promiscuous = promiscuous;
// 	}
// 
// 
// 	public InitialDirContext getBinding() throws NamingException {
// 		return new InitialDirContext(getProperties(url, lookupUserDN, lookupUserPassword, promiscuous));
// 	}
// 	
// 	public InitialDirContext getBinding(String lookupUserDN, String lookupUserPassword) throws NamingException {
// 		return new InitialDirContext(getProperties(url, lookupUserDN, lookupUserPassword, promiscuous));
// 	}
// 
// 	
// 	public Properties getProperties(String url, String username, String password, boolean promiscuous)
// 	{
// 		Properties properties = new Properties();
// 		properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
// 		properties.setProperty(Context.PROVIDER_URL, url);
// 		properties.setProperty(Context.SECURITY_PRINCIPAL, username);
// 		properties.setProperty(Context.SECURITY_CREDENTIALS, password);
// 		if (promiscuous){
// 			properties.setProperty("java.naming.ldap.factory.socket", PromiscuousSSLSocketFactory.class.getName());
// 		}
// 		return properties;
// 	}
// }


import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import com.asolutions.scmsshd.ldap.LDAPBindingProvider;
/**
 * 
 */
package com.asolutions.scmsshd.authenticators;



public class LDAPUsernameResolver {
	LDAPBindingProvider provider;
	private String userBase;
	private String matchingElement;
	public LDAPUsernameResolver(LDAPBindingProvider provider, String userBase) {
		this(provider, userBase, "cn=");
	}
	public LDAPUsernameResolver(LDAPBindingProvider provider, String userBase, String matchingElement) {
		this.provider = provider;
		this.userBase = userBase;
		this.matchingElement = matchingElement;
	}
	
// Path: src/main/java/com/asolutions/scmsshd/ldap/LDAPBindingProvider.java
// public class LDAPBindingProvider {
// 	private String lookupUserDN;
// 	private String lookupUserPassword;
// 	private String url;
// 	private boolean promiscuous;
// 	
// 	public LDAPBindingProvider(String lookupUserDN, String lookupUserPassword,
// 			String url, boolean promiscuous) {
// 		this.lookupUserDN = lookupUserDN;
// 		this.lookupUserPassword = lookupUserPassword;
// 		this.url = url;
// 		this.promiscuous = promiscuous;
// 	}
// 
// 
// 	public InitialDirContext getBinding() throws NamingException {
// 		return new InitialDirContext(getProperties(url, lookupUserDN, lookupUserPassword, promiscuous));
// 	}
// 	
// 	public InitialDirContext getBinding(String lookupUserDN, String lookupUserPassword) throws NamingException {
// 		return new InitialDirContext(getProperties(url, lookupUserDN, lookupUserPassword, promiscuous));
// 	}
// 
// 	
// 	public Properties getProperties(String url, String username, String password, boolean promiscuous)
// 	{
// 		Properties properties = new Properties();
// 		properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
// 		properties.setProperty(Context.PROVIDER_URL, url);
// 		properties.setProperty(Context.SECURITY_PRINCIPAL, username);
// 		properties.setProperty(Context.SECURITY_CREDENTIALS, password);
// 		if (promiscuous){
// 			properties.setProperty("java.naming.ldap.factory.socket", PromiscuousSSLSocketFactory.class.getName());
// 		}
// 		return properties;
// 	}
// }


// Path: src/main/java/com/asolutions/scmsshd/authenticators/LDAPUsernameResolver.java
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import com.asolutions.scmsshd.ldap.LDAPBindingProvider;

/**
 * 
 */
package com.asolutions.scmsshd.authenticators;



public class LDAPUsernameResolver {
	LDAPBindingProvider provider;
	private String userBase;
	private String matchingElement;
	public LDAPUsernameResolver(LDAPBindingProvider provider, String userBase) {
		this(provider, userBase, "cn=");
	}
	public LDAPUsernameResolver(LDAPBindingProvider provider, String userBase, String matchingElement) {
		this.provider = provider;
		this.userBase = userBase;
		this.matchingElement = matchingElement;
	}
	
	public String resolveUserName(String username) throws NamingException{