Remove Principals from a Group
The following code sample illustrates how to remove principals from a group.
Code Sample
See the C++ environment settings for details on setting the project environment.
<cpp_admin_group_removefrom_2.cpp>
/*****************************************************************************************
*
* cpp_admin_group_removefrom_2.cpp
*
*
******************************************************************************************/
#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
{
// Connect to server
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->());
// Set the group from which principals will be removed
te_oid groupID = 11001;
// Get group info
TEGroupInfo group;
group.setPrincipalId(groupID);
admin.getPrincipal(group, group);
cout << "Group ID = " << group.getPrincipalId() << endl;
cout << "Group Name = " << group.getGroupName() << endl;
cout << "Number of joined principals = " << group.PrincipalCount() << endl;
// Prepare the principal ID's to be removed
TEObjectContainer pcplIDs;
TEUInt32 id(1001);
pcplIDs.add(&id);
id = TEUInt32(1002);
pcplIDs.add(&id);
id = TEUInt32(3001);
pcplIDs.add(&id);
// Removes principals from a group.
admin.removePrincipalsFromGroup(groupID, pcplIDs);
cout << endl;
cout << "Principal was updated" << endl;
// Get the updated group info
admin.getPrincipal(group, group);
cout << "Group ID = " << group.getPrincipalId() << endl;
cout << "Group Name = " << group.getGroupName() << endl;
cout << "Number of joined principals = " << group.PrincipalCount() << endl;
admin.detachConnection();
// Disconnect from server
conn->close();
cout << endl << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
Output
Connected to localhost as admin
Group ID = 11001
Group Name = TestGroup
Number of joined principals = 3
Principal was updated
Group ID = 11001
Group Name = TestGroup
Number of joined principals = 0
Disconnected from localhost