Skip to main content

Get Principal by Name

The following code sample illustrates how to get a principal using a name.


Code Samples

See the C++ environment settings for details on setting the project environment.


<cpp_admin_principal_getbyname.cpp>
/*****************************************************************************************
*
* cpp_admin_principal_getbyname.cpp
*
*
******************************************************************************************/

#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin.h"
#include "tewinprincipal.h"
#include "teldapprincipal.h"

using namespace ERUCES;
using namespace std;

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

try
{
// Connect to server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
conn->open(strServer, nPort, strAdminUser, strAdminPswd);
cout << "Connected to " << strServer << " as " << strAdminUser << endl << endl;

TEAdmin admin;
admin.attachConnection(conn.operator->());

// Get a native user by name
TEUserAndPasswordInfo user;
user.setUserName("TestUser1");
admin.getPrincipalByName(user);
cout << "User ID = " << user.getPrincipalId() << endl;
cout << "User Name = " << user.getUserName().c_str() << endl;

admin.detachConnection();

// Disconnect from server
conn->close();
cout << endl << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}
Output
Connected to localhost as admin

User ID = 10007
User Name = TestUser1

Disconnected from localhost