#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teobjcontainer.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
{
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->());
TEObjectContainer contIDs;
TEObjectContainer contPrincipals;
TEOID id(10007);
contIDs.add(&id);
id = TEOID(10008);
contIDs.add(&id);
id = TEOID(10009);
contIDs.add(&id);
id = TEOID(10010);
contIDs.add(&id);
admin.getPrincipalByID(contIDs, contPrincipals);
cout << "\nPrincipals obtained: " << endl;
for (long i=0; i<contPrincipals.size(); i++)
{
cout << endl;
const TEPrincipalInfo* pPrcplInfo =
static_cast<const TEPrincipalInfo*>(contPrincipals[i]);
string strClassName = pPrcplInfo->getClassName();
cout << "Class name = " << strClassName << endl;
cout << "Number of Roles = " << pPrcplInfo->RoleCount() << endl;
if ( strClassName == "TEUserAndPasswordInfo" )
{
const TEUserAndPasswordInfo * pUser =
static_cast<const TEUserAndPasswordInfo *>( pPrcplInfo );
cout << "Native user ID = " << pUser->getPrincipalId() << endl;
cout << "Native user Name = " << pUser->getUserName() << endl;
}
else if ( strClassName == "TELDAPPrincipalInfo" )
{
const TELDAPPrincipalInfo * pLDAPuser =
static_cast<const TELDAPPrincipalInfo *>( pPrcplInfo );
cout << "LDAP user ID = " << pLDAPuser->getPrincipalId() << endl;
cout << "LDAP user Name = " << pLDAPuser->getName() << endl;
}
else if ( strClassName == "TEWindowsPrincipalInfo" )
{
const TEWindowsPrincipalInfo * pWinuser =
static_cast<const TEWindowsPrincipalInfo *>( pPrcplInfo );
cout << "Windows user ID = " << pWinuser->getPrincipalId() << endl;
cout << "Windows user Name = " << pWinuser->getUserName() << endl;
}
else if ( strClassName == "TEGroupInfo" )
{
const TEGroupInfo * pGroup = static_cast<const TEGroupInfo *>( pPrcplInfo );
cout << "Group ID = " << pGroup->getPrincipalId() << endl;
cout << "Group Name = " << pGroup->getGroupName() << endl;
}
else
cout << "Unknown class type !!!" << endl;
cout << endl;
}
admin.detachConnection();
conn->close();
cout << endl << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}