Skip to main content

Update Templated Directory

The following code sample illustrates how to update a templated directory.


Code Sample

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


<cpp_adminacl_templatedir_update.cpp>
/*****************************************************************************************
*
* cpp_adminacl_templatedir_update.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 *templatedDir2Update = NULL;

// List getTemplatedDirectory before updating TETemplatedDirectory
TEObjectContainer cont;
adminACL.getTemplatedDirectory(cont);
cout << "Before updating 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:\\TESTSECURE") {
templatedDir2Update = 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 (templatedDir2Update == NULL ) {
cout << "Required TETemplatedDirectory was not found." << endl;
goto FailureExit;
}

// Update TETemplatedDirectory
templatedDir2Update->setPath("C:\\TestSecure2");
adminACL.updateTemplatedDirectory(*templatedDir2Update);
cout << "TETemplatedDirectory was updated" << endl;

// List getTemplatedDirectory after updating TETemplatedDirectory
adminACL.getTemplatedDirectory(cont);
cout << "After updating 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 updating TETemplatedDirectory, Number of TemplatedDirectory = 1

TemplatedDirectoryId: 3
HostID: 0
Path: C:\TESTSECURE
Alias:
ACLTemplateId: 5
Flag : 0
TETemplatedDirectory was updated
After updating TETemplatedDirectory, Number of TemplatedDirectory = 1

TemplatedDirectoryId: 4
HostID: 0
Path: C:\TESTSECURE2
Alias:
ACLTemplateId: 5
Flag : 0
Disconnected from xyang
Press any key to continue