#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teobject.h"
#include "teadmin.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->());
TEUserAndPasswordInfo user;
user.setPrincipalId(3001);
admin.getPrincipal(user, user);
cout << "Principal info: " << endl;
cout << "User ID = " << user.getPrincipalId() << endl;
cout << "User Name = " << user.getUserName() << endl;
cout << "Number of joined groups = " << user.GroupCount() << endl;
TEObjectContainer groupIDs;
TEOID id(11001);
groupIDs.add(&id);
id = TEOID(11002);
groupIDs.add(&id);
admin.assignGroups(user, groupIDs);
cout << endl;
cout << "Principal was updated" << endl;
admin.getPrincipal(user, user);
cout << "User ID = " << user.getPrincipalId() << endl;
cout << "User Name = " << user.getUserName() << endl;
cout << "Number of joined groups = " << user.GroupCount() << 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;
}