#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
{
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 container;
int nType = 2;
admin.getPrincipalList(static_cast<TEAdmin::PRINCIPAL_LIST_TYPE>(nType), container);
if( container.size() > 0 )
{
cout << "\nPrincipals obtained: " << endl;
for (long i=0; i<container.size(); i++)
{
const TEPrincipalInfo* info = static_cast<const TEPrincipalInfo*>(container[i]);
cout << endl;
cout << "Class Name: " << info->getClassName() << endl;
cout << "Number of Roles: " << info->RoleCount() << endl;
if (nType == TEAdmin::PRINCIPAL_USERANDPASSWORD )
{
const TEUserAndPasswordInfo *pUser =
static_cast<const TEUserAndPasswordInfo*>(container[i]);
cout << "User Name: " << pUser->getUserName() << endl;
cout << "User ID : " << pUser->getPrincipalId() << endl;
}
else if (nType == TEAdmin::PRINCIPAL_LDAP )
{
const TELDAPPrincipalInfo *pLDAPUser =
static_cast<const TELDAPPrincipalInfo*>(container[i]);
cout << "LDAP user Name: " << pLDAPUser->getName() << endl;
cout << "LDAP user ID : " << pLDAPUser->getPrincipalId() << endl;
}
else if (nType == TEAdmin::PRINCIPAL_WINDOWS )
{
const TEWindowsPrincipalInfo *pUser =
static_cast<const TEWindowsPrincipalInfo*>(container[i]);
cout << "Windows user Name: " << pUser->getUserName() << endl;
cout << "Windows user ID : " << pUser->getPrincipalId() << endl;
}
else if (nType == TEAdmin::PRINCIPAL_GROUP )
{
const TEGroupInfo *pGroup =
static_cast<const TEGroupInfo*>(container[i]);
cout << "Group Name: " << pGroup->getGroupName() << endl;
cout << "Group ID : " << pGroup->getPrincipalId() << endl;
}
else
cout << "Unknown principal type.";
cout << endl;
}
}
else
cout << "\nNo principal was found !" << endl;
admin.detachConnection();
conn->close();
cout << "disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}