Skip to main content

Remove a Principal in Cpp

The following code sample illustrates how to remove a principal from the TE system.


Code Samples

See the C++ environment settings for details on setting the project environment.


<cpp_admin_principal_remove.cpp>
/*****************************************************************************************
*
* cpp_admin_principal_remove.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"
#include "teldapprincipal.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->());

TEUserAndPasswordInfo user_receiving_hls; // this user will receive hiddenlinks of deleted users
user_receiving_hls.setUserName("admin");
admin.getPrincipalByName(user_receiving_hls);

// Delete a native user
TEUserAndPasswordInfo user;
user.setUserName("TestUser1_modified");
admin.getPrincipalByName(user);
admin.removePrincipal(user, user_receiving_hls);

// Delete a LDAP user
TELDAPPrincipalInfo ldapuser;
ldapuser.setName("cn=joe_modified,o=emedna");
admin.getPrincipal(ldapuser, ldapuser);
admin.removePrincipal(ldapuser, user_receiving_hls);

// Delete a Windows user
TEWindowsPrincipalInfo winuser;
winuser.setUserName("SampleDomain/SampleUser_modified");
admin.getPrincipal(winuser, winuser);
admin.removePrincipal(winuser, user_receiving_hls);

// Delete a group
TEGroupInfo group;
group.setGroupName("TestGroup1_modified");
admin.getPrincipal(group, group);
admin.removePrincipal(group, user_receiving_hls);

cout << "Principals were removed." << 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

Principals were removed.

Disconnected from localhost