#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"
#include "teadmin_acl.h"
#include "teacl_template.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->());
TEGroupInfo group;
group.setGroupName("testgroup");
admin.getPrincipal(group, group);
int id2Remove = group.getPrincipalId();
TEUserAndPasswordInfo user;
user.setUserName("testuser");
admin.getPrincipal(user, user);
cout << "User ID = " << user.getPrincipalId() << endl;
cout << "User Name = " << user.getUserName() << endl << endl;
TEObjectContainer cont;
user.getGroupIds(cont);
cout << "Before removing group, number of groups = " << cont.size() << endl;
int i;
bool isFound = false;
for (i=0; i < cont.size(); ++i)
{
int groupID = ((TEUInt32*)cont[i])->getValue();
if (groupID == id2Remove) {
isFound = true;
}
cout << "\tGroup Id: " << groupID << endl;
}
if (!isFound) {
cout << "Required group is not in the list." << endl;
goto FailureExit;
}
user.removeGroup(id2Remove);
admin.updatePrincipal(user);
cout << "Group was removed from the principal." << endl;
admin.getPrincipal(user, user);
user.getGroupIds(cont);
cout << endl;
cout << "After removing group, number of reviewers = " << cont.size() << endl;
for (i=0; i < cont.size(); ++i)
{
int groupID = ((TEUInt32*)cont[i])->getValue();
cout << "\tGroup Id: " << groupID << endl;
}
FailureExit:
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;
}