Listing the Users of an ACL
Listing the users of an ACL.
Java_Admin_ACL_List_Trust.java
The following code sample illustrates how to list all the users included on an ACL of a T-Tag (referred to as HiddenLink in methods and objects) retrieved using the uri of the file.
/*****************************************************************************************
*
* Java_Admin_ACL_List_Trust.java
*
******************************************************************************************/
import java.util.Date;
import java.util.Iterator;
import java.util.TreeSet;
import com.eruces.teadmin.*;
import com.eruces.teagent.*;
public class Java_Admin_ACL_List_Trust {
private static final String m_strServ = "sampleserver"; // server to connect to
private static final int m_intPort = 8888; // port to connect through
private static final String m_strAdminUser = "ls"; // user to login as
private static final String m_strAdminPass = "password1A"; // password of login user
private static final String m_strFile = "util/test.txt.enc"; // file to get the ACL data from
private static TEAgentConnection m_conn;
public static void connect() throws TEAgentException { // standard way of connecting
m_conn = TEAgentConnectionFactory.getInstance(TEAgentConnectionFactory.SECURE_USER_PASSWORD);
m_conn.open(m_strServ, m_intPort, m_strAdminUser, m_strAdminPass);
System.out.println("Connected to " + m_strServ + ":" + m_intPort + " as " + m_strAdminUser + ".");
}
public static void disconnect() throws TEAgentException { // standard way of disconnecting
m_conn.close();
System.out.println("Disconnected from " + m_strServ + ":" + m_intPort + " as " + m_strAdminUser + ".");
}
public static String getHiddenLink(String strFileName) throws TEAgentException {
TEAgentFile agent = new TEAgentFile(strFileName);
return agent.getHiddenLinkFromFile();
}
public static void getACL(String strHiddenLink) throws TEAgentException, AdminException
{
Administration admin = new Administration();
admin.attachConnection(m_conn);
try {
ACLInfo info = admin.getACL(strHiddenLink);
System.out.println("ACL Info for File \"" + m_strFile + "\":");
System.out.println("\t" + "T-tag: " + info.getHiddenLink());
System.out.println("\t" + "Hash Code: " + info.hashCode());
System.out.println("\t" + "Created: " + new Date(info.getCreationTimeStamp().getTime() * 1000));
System.out.println("\t" + "Entries: " + info.getACLEntryCount());
TreeSet<?> entries = info.getAllEntries(); // Turn the ACL entries into a 'TreeSet<>' object.
PList plist = new PList();
Iterator<?> iter = entries.iterator();
while (iter.hasNext()) { // Iterate through all of the ACL entries.
ACLEntry entry = (ACLEntry)iter.next();
long usr_id = entry.getPrincipalID();
plist.add(usr_id);
}
PrincipalInfo[] pinfo = admin.getPrincipalList(plist);
for (int i = 0; i < pinfo.length; i ++) {
PrincipalInfo user = pinfo[i];
System.out.println("ACL Entry:");
System.out.println("\t" + "User Name: " + user.getPrincipalName());
System.out.println("\t" + "User ID: " + user.getPrincipalID());
System.out.println("\t" + "User Type: " + user.getClass().toString());
System.out.println("\t" + "System ID: " + user.getSystemID());
}
}
catch (TEServerException tse) {
System.out.println("The user accessing the ACL must be the owner of the T-tag.");
}
finally {
admin.detachConnection();
}
}
public static void main(String[] args)
{
try {
connect();
System.out.println();
getACL(getHiddenLink(m_strFile)); // Generate a T-tag from the specified file and get the ACL info for it.
System.out.println();
disconnect();
}
catch (Exception ex) {
System.out.println("Exception encountered: ");
ex.printStackTrace();
}
}
}
// Connected to sampleserver:8888 as ls.
//
//
//ACL Info for File "util/test.txt.enc":
// T-tag: AAAAAa7+3sJYZTY4YUNTbECtl6607Rmsrp2vDpCdmoME6aLB/xIjQw==
// Hash Code: 427451634
// Created: Tue Apr 15 12:50:14 CDT 2014
// Entries: 4
//ACL Entry:
// User Name: user
// User ID: 1002
// User Type: class com.eruces.teadmin.UserAndPasswordInfo
// System ID: 1
//ACL Entry:
// User Name: testuser1
// User ID: 3001
// User Type: class com.eruces.teadmin.UserAndPasswordInfo
// System ID: 1
//ACL Entry:
// User Name: testuser2
// User ID: 3002
// User Type: class com.eruces.teadmin.UserAndPasswordInfo
// System ID: 1
//ACL Entry:
// User Name: testuser3
// User ID: 3003
// User Type: class com.eruces.teadmin.UserAndPasswordInfo
// System ID: 1
//
//
//Disconnected from sampleserver:8888 as ls.