Skip to main content

Java_Admin_Group_Remove.java

/****************************************************************************************
*
*
* Java_Admin_Group_Remove.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.GroupInfo;
import com.eruces.teadmin.PrincipalInfo;
import com.eruces.teadmin.UserAndPasswordInfo;



public class Java_Admin_Group_Remove
{

private String m_strServerName;

private int m_nPort;

private String m_strUsername;

private String m_strPasswd;

private TEAgentConnection m_conn;



public void removeGroup() throws TEAgentException, AdminException, Exception
{
Administration admin = new Administration();
admin.attachConnection(m_conn);

// Find Group

GroupInfo groupInfo = new GroupInfo("AddedGroup1");


groupInfo = (GroupInfo)admin.getPrincipal(groupInfo);

if( groupInfo == null )
throw new Exception("Getting group failed !");

System.out.println("");
System.out.println("Group was got:");
System.out.println(" " + groupInfo.toString());




// The group's keys must be handed to a surviving principal, which is named
// here by user name; that principal receives the keys from the removed group.

PrincipalInfo principalKey = admin.getUserByName(m_strUsername);

admin.removePrincipal(groupInfo, principalKey); // remove group, reassigning its keys

System.out.println("");
System.out.println("Principal was removed.");

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_Group_Remove test = new Java_Admin_Group_Remove();

test.connect("sampleserver", 8889, "sadmin", "password1A");

test.removeGroup();

test.disconnect();

}
catch (TEAgentException te) {

System.out.println("TEAgentException encountered: ");

te.printStackTrace();

}
catch (AdminException te) {

System.out.println("AdminException encountered: ");

te.printStackTrace();

}
catch (Exception ex) {

System.out.println("Exception encountered: ");

ex.printStackTrace();

}
}
}