Skip to main content

Java_Admin_Principal_AclTemplate_set.java

/*****************************************************************************************
*
* Java_Admin_Principal_AclTemplate_set.java
*
******************************************************************************************/

import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TEAgentException;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teadmin.Administration;
import com.eruces.teadmin.AdminException;
import com.eruces.teadmin.ACLAdmin;
import com.eruces.teadmin.ACLTemplate;
import com.eruces.teadmin.UserAndPasswordInfo;

public class Java_Admin_Principal_AclTemplate_set {
private String m_strServerName;
private int m_nPort;
private String m_strUsername;
private String m_strPasswd;
private TEAgentConnection m_conn;

public void test_setACLTemplate() throws TEAgentException, AdminException {
// Create ACLAdmin
ACLAdmin aclAdmin = new ACLAdmin();
aclAdmin.attachConnection(m_conn);

ACLTemplate theACLTemplate = null;

// Get the required ACLTemplates
ACLTemplate[] allACLTemplates = aclAdmin.getACLTemplate();
for (int i = 0; i < allACLTemplates.length; i++) {
ACLTemplate aclTemplate = allACLTemplates[i];
if (aclTemplate.getName().equals("TestTemplate2")) {
theACLTemplate = aclTemplate;
break;
}
}
aclAdmin.detachConnection();

if (theACLTemplate == null) {
System.out.println("ACLTemplate (TestTemplate2) was not found");
return;
}
System.out.println(theACLTemplate.toString());


// Set ACLTemplateID and update principal
Administration admin = new Administration();
admin.attachConnection(m_conn);
UserAndPasswordInfo testUser = (UserAndPasswordInfo) admin.getUserByName("testuser");
testUser.setAclTemplateId(theACLTemplate.getACLTemplateID());
admin.updatePrincipal(testUser);

System.out.println("Principal was updated with ACLTemplateID = " + theACLTemplate.getACLTemplateID());
System.out.println(testUser.toString());

admin.detachConnection();
}

public void connect(String strServerName, int nPort, String strUsername, String strPasswd) throws TEAgentException {
m_strServerName = strServerName;
m_nPort = nPort;
m_strUsername = strUsername;
m_strPasswd = strPasswd;

m_conn = TEAgentConnectionFactory.getInstance(TEAgentConnectionFactory.SECURE_USER_PASSWORD);
// Connect to server.
m_conn.open(m_strServerName, m_nPort, m_strUsername, m_strPasswd);
System.out.println("Connected to " + m_strServerName + " at " + m_nPort + " as " + m_strUsername);
}

public void disconnect() throws TEAgentException {
m_conn.close(); // disconnect from the server.
System.out.println("Disconnected from " + m_strServerName);
}

public static void main(String[] args) {
try {

Java_Admin_Principal_AclTemplate_set test = new Java_Admin_Principal_AclTemplate_set();
test.connect("sampleserver", 8888, "admin", "password1A");
test.test_setACLTemplate();
test.disconnect();
}
catch (TEAgentException te) {
System.out.println("TEAgentException encountered: ");
te.printStackTrace();
}
catch (AdminException adminex) {
System.out.println("AdminException encountered: ");
adminex.printStackTrace();
}
catch (Exception ex) {
System.out.println("Exception encountered: ");
ex.printStackTrace();
}
}
}


/*
Connected to sampleserver at 8888 as admin
ACLTemplate:
<ACLTemplate ID: 2 >
<ACLTemplate Name: TestTemplate2 >
<ACLTemplate Flag: 1 >
<Number of ACLTemplateMembers: 4 >
ACLTemplateMember:
<Principal ID: 1 >
<System ID: 1 >
<ACLTemplate ID: 2 >
<Rights: 769 >
<Start Time: 0 >
<End Time: 0 >
<MaxUsage: -1 >
ACLTemplateMember:
<Principal ID: 3002 >
<System ID: 1 >
<ACLTemplate ID: 2 >
<Rights: 257 >
<Start Time: 0 >
<End Time: 0 >
<MaxUsage: -1 >
ACLTemplateMember:
<Principal ID: 3003 >
<System ID: 1 >
<ACLTemplate ID: 2 >
<Rights: 257 >
<Start Time: 0 >
<End Time: 0 >
<MaxUsage: -1 >
ACLTemplateMember:
<Principal ID: 3004 >
<System ID: 1 >
<ACLTemplate ID: 2 >
<Rights: 257 >
<Start Time: 0 >
<End Time: 0 >
<MaxUsage: -1 >

Principal was updated with ACLTemplateID = 2
UserAndPasswordInfo:
UpdatableObject: <>
<System ID: 1 >
<Principal ID: 3004 >
<Role ID List: PList: {[<9,2>]} >
<Group ID List: PList: {[]} >
<Default Group ID: 0 >
<Reviewer ID List: PList: {[]} >
<ACL Template ID: 2 >
<User Name: testuser >

Disconnected from sampleserver

*/