// Path: src/main/java/com/asolutions/scmsshd/ssl/PromiscuousSSLSocketFactory.java
// public class PromiscuousSSLSocketFactory extends SocketFactory {
// 	protected final Logger log = LoggerFactory.getLogger(getClass());
// 	private static SocketFactory blindFactory = null;
// 
// 	/**
// 	 * 
// 	 * Builds an all trusting "blind" ssl socket factory.
// 	 * 
// 	 */
// 
// 	static {
// 		// create a trust manager that will purposefully fall down on the
// 		// job
// 		TrustManager[] blindTrustMan = new TrustManager[] { new X509TrustManager() {
// 			public X509Certificate[] getAcceptedIssuers() {
// 				return null;
// 			}
// 			public void checkClientTrusted(X509Certificate[] c, String a) {
// 			}
// 			public void checkServerTrusted(X509Certificate[] c, String a) {
// 			}
// 		} };
// 
// 		// create our "blind" ssl socket factory with our lazy trust manager
// 		try {
// 			SSLContext sc = SSLContext.getInstance("SSL");
// 			sc.init(null, blindTrustMan, new java.security.SecureRandom());
// 			blindFactory = sc.getSocketFactory();
// 		} catch (GeneralSecurityException e) {
// 			LoggerFactory.getLogger(PromiscuousSSLSocketFactory.class).error("Error taking security promiscuous" , e);
// 		}
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#getDefault()
// 	 * 
// 	 */
// 
// 	public static SocketFactory getDefault() {
// 		return new PromiscuousSSLSocketFactory();
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(String arg0, int arg1) throws IOException,
// 	UnknownHostException {
// 		return blindFactory.createSocket(arg0, arg1);
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(InetAddress arg0, int arg1) throws IOException {
// 		return blindFactory.createSocket(arg0, arg1);
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.lang.String, int,
// 	 * 
// 	 * java.net.InetAddress, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3)
// 	throws IOException, UnknownHostException {
// 		return blindFactory.createSocket(arg0, arg1, arg2, arg3);
// 
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int,
// 	 * 
// 	 * java.net.InetAddress, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException {
// 		return blindFactory.createSocket(arg0, arg1, arg2, arg3);
// 	}
// 
// }


import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import com.asolutions.scmsshd.ssl.PromiscuousSSLSocketFactory;
/**
 * 
 */
package com.asolutions.scmsshd.ldap;




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){
// Path: src/main/java/com/asolutions/scmsshd/ssl/PromiscuousSSLSocketFactory.java
// public class PromiscuousSSLSocketFactory extends SocketFactory {
// 	protected final Logger log = LoggerFactory.getLogger(getClass());
// 	private static SocketFactory blindFactory = null;
// 
// 	/**
// 	 * 
// 	 * Builds an all trusting "blind" ssl socket factory.
// 	 * 
// 	 */
// 
// 	static {
// 		// create a trust manager that will purposefully fall down on the
// 		// job
// 		TrustManager[] blindTrustMan = new TrustManager[] { new X509TrustManager() {
// 			public X509Certificate[] getAcceptedIssuers() {
// 				return null;
// 			}
// 			public void checkClientTrusted(X509Certificate[] c, String a) {
// 			}
// 			public void checkServerTrusted(X509Certificate[] c, String a) {
// 			}
// 		} };
// 
// 		// create our "blind" ssl socket factory with our lazy trust manager
// 		try {
// 			SSLContext sc = SSLContext.getInstance("SSL");
// 			sc.init(null, blindTrustMan, new java.security.SecureRandom());
// 			blindFactory = sc.getSocketFactory();
// 		} catch (GeneralSecurityException e) {
// 			LoggerFactory.getLogger(PromiscuousSSLSocketFactory.class).error("Error taking security promiscuous" , e);
// 		}
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#getDefault()
// 	 * 
// 	 */
// 
// 	public static SocketFactory getDefault() {
// 		return new PromiscuousSSLSocketFactory();
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(String arg0, int arg1) throws IOException,
// 	UnknownHostException {
// 		return blindFactory.createSocket(arg0, arg1);
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(InetAddress arg0, int arg1) throws IOException {
// 		return blindFactory.createSocket(arg0, arg1);
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.lang.String, int,
// 	 * 
// 	 * java.net.InetAddress, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3)
// 	throws IOException, UnknownHostException {
// 		return blindFactory.createSocket(arg0, arg1, arg2, arg3);
// 
// 	}
// 
// 	/**
// 	 * 
// 	 * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int,
// 	 * 
// 	 * java.net.InetAddress, int)
// 	 * 
// 	 */
// 
// 	@Override
// 	public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException {
// 		return blindFactory.createSocket(arg0, arg1, arg2, arg3);
// 	}
// 
// }


// Path: src/main/java/com/asolutions/scmsshd/ldap/LDAPBindingProvider.java
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import com.asolutions.scmsshd.ssl.PromiscuousSSLSocketFactory;

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




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());