Skip to main content

cpp_connect_ldap.cpp

/*****************************************************************************************
* cpp_connect_ldap.cpp
*
* Note: See Tricryption Engine SDK for details on how to set the project environment.
*
******************************************************************************************/

#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"
#include "teauthldapctx.h"

using namespace ERUCES;
using namespace std;


int main()
{
string strServerName = "localhost"; // server name
long lPort = 8888; // port number
string strUsername = "cn=bob,o=emedna"; // LDAP username
string strPassword = "bob"; // password

try
{
auto_ptr<TEConnection> conn =
TEConnection::createInstance(TEConnection::SecureConnection);

// Open connection to the server for LDAP user
auto_ptr<TELdapAuthenticationContext> ctx =
TELdapAuthenticationContext::getInstance();
ctx->setUser(strUsername);
ctx->setPasswd(strPassword);

conn->open(strServerName, lPort, *ctx.operator->());

cout << "Connected to " << strServerName << " at " << lPort
<< " as " << strUsername << "\n" << endl;

// Close conneciton
conn->close();

cout << "Disconnected from server." << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}