Skip to main content

Remove Roles from a Principal

Removing multiple roles to a principal


Code Samples

See the Java environment settings for details on setting the project environment.


Java_Admin_Role_RemoveFrom

The following code sample illustrates how to remove multiple roles from a principal.

/*****************************************************************************************
*
* Java_Admin_Role_RemoveFrom.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.UserAndPasswordInfo;
public class Java_Admin_Role_RemoveFrom
{
private String m_strServerName;
private int m_nPort;
private String m_strUsername;
private String m_strPasswd;
private TEAgentConnection m_conn;
public void removeRolesFromPrincipal() throws TEAgentException, AdminException
{
Administration admin = new Administration();
admin.attachConnection(m_conn);
// Get a native user for update
UserAndPasswordInfo principal = new UserAndPasswordInfo();
principal.setUserName("ls");
principal = (UserAndPasswordInfo)admin.getPrincipal(principal);
int [] roleIDs = new int[3];
roleIDs[0] = 1; // ADMINISTRATOR role
roleIDs[1] = 2; // ENCRYPTOR role
roleIDs[2] = 3; // EXCHANGER role
admin.removeRoles(principal, roleIDs); // remove roles from principal
System.out.println("Roles were removed to the principal.");
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_Role_RemoveFrom test = new Java_Admin_Role_RemoveFrom();
test.connect("sampleserver", 8888, "admin", "password1A");
test.removeRolesFromPrincipal();
test.disconnect();
}
catch (TEAgentException te) {
System.out.println("TEAgentException encountered: ");
te.printStackTrace();
}
catch (AdminException te) {
System.out.println("AdminException encountered: ");
te.printStackTrace();
}
}
}
Output
Connected to sampleserver at 8888 as admin
Roles were removed to the principal.
Disconnected from sampleserver