Skip to main content

Working with Templated Directories

Assigning ACL Templates to directories for creating ACLs based on file locations.


Sample_Admin_Template_Directory_Operations.java

The following code sample illustrates how to create a Templated Directory by associating a directory with an ACL Template and how to remove the association.

import java.util.Vector;
import com.eruces.teadmin.ACLAdmin;
import com.eruces.teadmin.ACLTemplate;
import com.eruces.teadmin.TemplatedDirectory;
import com.eruces.teagent.TEAgentConnection;
public class Sample_Admin_Template_Directory_Operations {
public static Vector<String> listAllTemplateDirectories(TEAgentConnection conn) {

Vector<String> out = new Vector<String>();
try {
ACLAdmin admin_acl = new ACLAdmin();
admin_acl.attachConnection(conn);

TemplatedDirectory[] directories = admin_acl.getTemplatedDirectories();

for (int i = 0; i < directories.length; i++)
{
out.add(directories[i].getAlias());
}

System.out.println("Retrieved " + out.size() + " templated directories.");

admin_acl.detachConnection();
}
catch (Exception e) {
e.printStackTrace();
}

return out;
}

public static void createTemplateDirectory(TEAgentConnection conn, String path_name, String temp_name) {

try {

ACLAdmin admin_acl = new ACLAdmin();
admin_acl.attachConnection(conn);

ACLTemplate template = new ACLTemplate();
template.setName(temp_name);
template = admin_acl.getACLTemplate(template);
TemplatedDirectory directory = new TemplatedDirectory();
directory.setAclTemplateId(template.getACLTemplateID());
directory.setPath(path_name.toUpperCase());
directory = admin_acl.addTemplatedDirectory(directory);

System.out.println("Added templated directory \"" + path_name + "\" with ACL template \"" + temp_name + "\".");

admin_acl.detachConnection();
}
catch (Exception e) {
e.printStackTrace();
}

}

public static void removeTemplateDirectory(TEAgentConnection conn, String path_name) {

try {
ACLAdmin admin_acl = new ACLAdmin();
admin_acl.attachConnection(conn);

TemplatedDirectory directory = admin_acl.getTemplatedDirectory(path_name.toUpperCase());
long id = directory.getAclTemplateId();

// For information only.
ACLTemplate template = new ACLTemplate();
template.setACLTemplateID(id);
template = admin_acl.getACLTemplate(template);
String temp_name = template.getName();

admin_acl.removeTemplatedDirectory(directory);

System.out.println("Removed templated directory \"" + path_name + "\" with ACL template \"" + temp_name + "\".");

admin_acl.detachConnection();
}
catch (Exception e) {
e.printStackTrace();
}
}

public static void changeTemplateDirectory(TEAgentConnection conn, String path_name, String new_path_name) {
try {

ACLAdmin admin_acl = new ACLAdmin();
admin_acl.attachConnection(conn);
TemplatedDirectory directory = admin_acl.getTemplatedDirectory(path_name.toUpperCase());

directory.setPath(new_path_name.toUpperCase());

admin_acl.updateTemplatedDirectory(directory);

System.out.println("Changed templated directory \"" + path_name + "\" to path \"" + new_path_name + "\".");

admin_acl.detachConnection();
}
catch (Exception e) {
e.printStackTrace();
}
}

}