#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"
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 role = " << user.RoleCount() << endl;
TEObjectContainer roleIDs;
TEOID id(1);
roleIDs.add(&id);
id = TEOID(2);
roleIDs.add(&id);
id = TEOID(3);
roleIDs.add(&id);
admin.removeRoles(user, roleIDs);
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 role = " << user.RoleCount() << 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;
}