import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TEAgentException;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teagent.LDAPAuthenticationContext;
import com.eruces.teagent.TEConnectionType;
public class Java_Connect_LDAP
{
private String m_strServerName;
private int m_nPort;
private String m_strUsername;
private String m_strPasswd;
private TEAgentConnection m_conn;
public void connect(String strServerName, int nPort, String strUsername, String strPasswd) throws TEAgentException
{
m_strServerName = strServerName;
m_nPort = nPort;
m_strUsername = strUsername;
m_strPasswd = strPasswd;
m_conn = TEAgentConnectionFactory.getConnection(TEConnectionType.SECURE_SOCKET);
LDAPAuthenticationContext ctx = LDAPAuthenticationContext.getInstance();
ctx.setUser(m_strUsername);
ctx.setPasswd(m_strPasswd);
m_conn.open(m_strServerName, m_nPort, ctx);
System.out.println("Connected to " + m_strServerName + " at " + m_nPort + " as " + ctx.getUser());
}
public void disconnect() throws TEAgentException
{
m_conn.close();
System.out.println("Disconnected from " + m_strServerName);
}
public static void main(String[] args)
{
try
{
Java_Connect_LDAP java_connect = new Java_Connect_LDAP();
java_connect.connect("sampleserver", 8888, "cn=bob,cn=users,dc=example,dc=com", "password1A");
java_connect.disconnect();
}
catch (TEAgentException te)
{
te.printStackTrace();
}
}
}