package com.tm.jndi.tests;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import com.tm.jndi.ldap.JndiLdapConnection;
import java.io.IOException;
import com.tm.jndi.ldap.ConnectionException;

public class LDAPTest
{
  private JndiLdapConnection jlc = null;

  public LDAPTest() 
  {
    jlc = new JndiLdapConnection();
  }

  public void authenticate()
  {
    try {
      System.out.println("Enter username: " );
      String username = (new BufferedReader(new InputStreamReader(System.in))).readLine();
      System.out.println("Enter password: " );
      String password =  (new BufferedReader(new InputStreamReader(System.in))).readLine();
      jlc.connect("localhost", "389", "dc=thinkmiddleware,dc=com",username, password);
      System.out.println("Authentication Successful.");
      jlc.close();
    } catch(IOException e) {
      e.printStackTrace();
    } catch (ConnectionException e) {
      e.printStackTrace();
    }
  }

  public static void main(String args[])
  {
    try {
      LDAPTest lt = new LDAPTest();
      lt.authenticate();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
