Skip to main content

Get ACL Template in Cpp

The following code sample illustrates how to get ACL templates.


Code Sample

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


<cpp_adminacl_acltemplate_get.cpp>
/*****************************************************************************************
*
* cpp_adminacl_acltemplate_get.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"

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->());

// List ACLTemplates
TEObjectContainer cont;
adminACL.getACLTemplate(cont);
cout << "Number of ACLTemplates = " << cont.size() << endl;
int i, j;
for (i=0; i < cont.size(); ++i)
{
TEACLTemplate *aclTemplate = (TEACLTemplate*)cont[i];
cout << endl;
cout << "\tACLTemplateId: " << aclTemplate->getACLTemplateId() << endl;
cout << "\tName: " << aclTemplate->getName() << endl;
cout << "\tFlag : " << aclTemplate->getFlag () << endl;

TEObjectContainer cont2;

aclTemplate->getMembers(cont2);
cout << "\tNumber of Members: " << cont2.size() << endl;
for (j=0; j < cont2.size(); ++j)
{
TEACLTemplateMember *member = (TEACLTemplateMember*)cont2[j];
cout << endl;
cout << "\t\tPrincipalId: " << member->getPrincipalId() << endl;
cout << "\t\tSystemId: " << member->getSystemId() << endl;
cout << "\t\tRight: " << member->getRight() << endl;
cout << "\t\tACLTemplateId: " << member->getACLTemplateId() << endl;
cout << "\t\tStartTime: " << member->getStartTime() << endl;
cout << "\t\tEndTime: " << member->getEndTime() << endl;
cout << "\t\tMaxUsage: " << member->getMaxUsage() << endl;
}
}

// 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
Number of ACLTemplates = 1

ACLTemplateId: 4
Name: TestTemplate
Flag : 1
Number of Members: 2

PrincipalId: 1
SystemId: 1
Right: 768
ACLTemplateId: 4
StartTime: 0
EndTime: 0
MaxUsage: 4294967295

PrincipalId: 3004
SystemId: 1
Right: 768
ACLTemplateId: 4
StartTime: 0
EndTime: 0
MaxUsage: 4294967295
Disconnected from xyang
Press any key to continue