Remove Templated Directory
The following code sample illustrates how to remove a templated directory.
Code Sample
See the C++ environment settings for details on setting the project environment.
<cpp_adminacl_templatedir_remove.cpp>
/*****************************************************************************************
*
* cpp_adminacl_templatedir_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_local.h"
#include "teadmin_acl.h"
#include "teacl_template.h"
#include "tetemplateddirectory.h"
using namespace ERUCES;
using namespace std;
int main()
{
string strServer = "xyang";
long nPort = 8888;
string strAdminUser = "admin";
string strAdminPswd = "password1A";
try
{
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection); // Use SecureConnection here
// Open connection to the server for native user
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strAdminUser);
ctx->setPasswd(strAdminPswd);
conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strAdminUser << " at port " << nPort << endl;
TEAdminACL adminACL;
adminACL.attachConnection(conn.operator->());
TETemplatedDirectory *templatedDir2Remove = NULL;
// List getTemplatedDirectory before removing TETemplatedDirectory
TEObjectContainer cont;
adminACL.getTemplatedDirectory(cont);
cout << "Before removing TETemplatedDirectory, Number of TemplatedDirectory = " << cont.size() << endl;
int i;
for (i=0; i < cont.size(); ++i)
{
TETemplatedDirectory *templatedDirectory = (TETemplatedDirectory*)cont[i];
if (templatedDirectory->getPath() == "C:\\TESTSECURE2") {
templatedDir2Remove = templatedDirectory;
}
cout << endl;
cout << "\tTemplatedDirectoryId: " << templatedDirectory->getId() << endl;
cout << "\tHostID: " << templatedDirectory->getHostId() << endl;
cout << "\tPath: " << templatedDirectory->getPath() << endl;
cout << "\tAlias: " << templatedDirectory->getAlias() << endl;
cout << "\tACLTemplateId: " << templatedDirectory->getAclTemplateId() << endl;
cout << "\tFlag : " << templatedDirectory->getFlag () << endl;
}
if (templatedDir2Remove == NULL ) {
cout << "Required TETemplatedDirectory was not found." << endl;
goto FailureExit;
}
// Remove TETemplatedDirectory
adminACL.removeTemplatedDirectory(*templatedDir2Remove);
cout << "TETemplatedDirectory was removed" << endl;
// List getTemplatedDirectory after removing new TETemplatedDirectory
adminACL.getTemplatedDirectory(cont);
cout << "After removing TETemplatedDirectory, Number of TemplatedDirectory = " << cont.size() << endl;
for (i=0; i < cont.size(); ++i)
{
TETemplatedDirectory *templatedDirectory = (TETemplatedDirectory*)cont[i];
cout << endl;
cout << "\tTemplatedDirectoryId: " << templatedDirectory->getId() << endl;
cout << "\tHostID: " << templatedDirectory->getHostId() << endl;
cout << "\tPath: " << templatedDirectory->getPath() << endl;
cout << "\tAlias: " << templatedDirectory->getAlias() << endl;
cout << "\tACLTemplateId: " << templatedDirectory->getAclTemplateId() << endl;
cout << "\tFlag : " << templatedDirectory->getFlag () << endl;
}
FailureExit:
// Disconnect from server
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
Output
Connected to xyang as admin at port 8888
Before removing TETemplatedDirectory, Number of TemplatedDirectory = 1
TemplatedDirectoryId: 4
HostID: 0
Path: C:\TESTSECURE2
Alias:
ACLTemplateId: 5
Flag : 0
TETemplatedDirectory was removed
After removing TETemplatedDirectory, Number of TemplatedDirectory = 0
Disconnected from xyang
Press any key to continue