Skip to main content

cpp_admin_connect.cpp

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

#include<string>
#include<iostream>

#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin_local.h"

using namespace ERUCES;
using namespace std;


int main()
{
string strServer = "localhost";
long nPort = 8888;
string strAdminUser = "admin";
string strAdminPswd = "password1A";

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

bool bUseContext = false;

// Connect to server
if( bUseContext )
{
// Open connection to the server for native user
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strAdminUser);
ctx->setPasswd(strAdminPswd);

conn->open(strServer, nPort, *ctx.operator->());
}
else
conn->open(strServer, nPort, strAdminUser, strAdminPswd);

cout << "Connected to " << strServer << " as " << strAdminUser
<< " at port " << nPort << endl;

// Disconnect from server
conn->close();

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

return 0;
}