Skip to main content

Get ACL Information in Cpp

The following code sample illustrates how to get a TEACLInfo object.


Code Sample

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


<cpp_admin_acl_get.cpp>
/*****************************************************************************************
*
* cpp_admin_acl_get.cpp
*
*
******************************************************************************************/

#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teobject.h"
#include "teadmin.h"

using namespace ERUCES;
using namespace std;

string generateTtag(string strServer, long nTlsPort string strUser, string strPswd);

int main()
{
string strServer = "localhost";
long nTlsPort = 8888;

string strAdminUser = "ls";
string strAdminPswd = "password";

try
{
// Set the T-tag for which the ACLInfo will be got.
string strHL = generateTtag(strServer, nTlsPort, strAdminUser, strAdminPswd);

// Connect to server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);

auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strAdminUser);
ctx->setPasswd(strAdminPswd);

conn->open(strServer, nTlsPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strAdminUser << endl;

TEAdmin admin;
admin.attachConnection(conn.operator->());

TEACLInfo acl;
admin.getACL(strHL, acl, true);

cout << "ACLInfo: " << endl;
cout << "\tACLID: " << acl.getACLId() << endl;
cout << "\tExpiration Flag: " << acl.getKeyExpirationFlag() << endl;
cout << "\tNumber of ACL entries: " << acl.EntryCount() << endl;

TEObjectContainer cont;
acl.getEntries(cont);
for (int i=0; i < cont.size(); ++i)
{
TEACLEntry *ent = (TEACLEntry*)cont[i];
cout << endl;
cout << "\tACLID: " << ent->getACLId() << endl;
cout << "\tACLRight: " << ent->getACLRight() << endl;
cout << "\tCreationTimestamp: " << ent->getCreationTimestamp() << endl;
cout << "\tEndTimestamp: " << ent->getEndTimestamp() << endl;
cout << "\tMaxUsage: " << ent->getMaxUsage() << endl;
cout << "\tPrincipalId: " << ent->getPrincipalId() << endl;
cout << "\tStartTimestamp: " << ent->getStartTimestamp() << endl;
cout << "\tSystemID: " << ent->getSystemID() << endl;
cout << "\tUserRight: " << ent->getUserRight() << endl;
}

admin.detachConnection();

// 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;
}

string generateTtag(string strServer, long nTlsPort, string strUser, string strPswd)
{
string strTtag = "";

auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::NormalConnection);

// Open connection to the server
conn->open(strServer, nTlsPort strUser, strPswd);

cout << "Connected to " << strServer << " at " << nTlsPort
<< " as " << strUser << "\n" << endl;

// Create TEAgentMatrix object
TEAgentMatrix matrix;

// Set matrix for encryption
matrix.setElement(1, 1, "dummy data for creating T-tag"); // set element (1, 1)

// Encrypt matrix
matrix.attachConnection(conn.operator->()); // Attach connection
matrix.encrypt();
matrix.detachConnection(); // Detach connection

// Get T-tag
matrix.setEncodeMode(true);

matrix.getHiddenLink(1, strTtag); // T-tag for first row

cout << "T-tag: " << strTtag << endl;

// Close conneciton
conn->close();
cout << "Disconnected from " << strServer << endl;

return strTtag;
}
Output
Connected to localhost at 8888 as ls

T-tag: AAAAAVXnjUz6hsXRtV3AynH7Etv37oXw1mja2hpsQsGWirLQf8vP6Q==
Disconnected from localhost
Connected to localhost as ls
ACLInfo:
ACLID: 9004
Expiration Flag: 0
Number of ACL entries: 1

ACLID: 9004
ACLRight: 7
CreationTimestamp: 1120230585
EndTimestamp: 0
MaxUsage: 4294967295
PrincipalId: 3001
StartTimestamp: 0
SystemID: 1
UserRight: 0
Disconnected from localhost