Skip to main content

Get Principal Trust Matrix Element

The principal trust matrices control the visibility of users across key servers.  For a more detailed explanation please review, Principal Trust Visibility Settings in the kS documentation.


Code Samples

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


Java_TrustedServerAdmin_Get_PrincipalTrustMatrix

The following code sample illustrates how to get principal trust matrix element.

/*****************************************************************************************
*
* Java_TrustedServerAdmin_Add_PrincipalTrustMatrix.java
*
******************************************************************************************/
import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TEAgentException;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teagent.TEConnectionType;
import com.eruces.teagent.TEAuthenticationType;
import com.eruces.teagent.UPAuthenticationContext;
import com.eruces.teadmin.TrustedServerAdmin;
import com.eruces.teadmin.PrincipalTrustMatrix;
public class Java_TrustedServerAdmin_Add_PrincipalTrustMatrix {
private String m_strServerName;
private int m_nPort;
private String m_strNativeUsername; // Native user
private String m_strNativePassword;
private TEAgentConnection m_conn;
private String m_strCookie;
public void connect_native(String strServerName, int nPort, String strUsername, String strPasswd) throws
TEAgentException {
m_strServerName = strServerName;
m_nPort = nPort;
m_strNativeUsername = strUsername;
m_strNativePassword = strPasswd;
// Get a connection instance
m_conn = TEAgentConnectionFactory.getConnection(TEConnectionType.SECURE_SOCKET); // SSL connection
// Make connection
UPAuthenticationContext ctx = (UPAuthenticationContext) TEAgentConnectionFactory.getAuthenticationContext(
TEAuthenticationType.USERANDPASSWORD);
ctx.setUser(m_strNativeUsername);
ctx.setPasswd(m_strNativePassword);
m_conn.open(m_strServerName, m_nPort, ctx);
m_strCookie = m_conn.getEncodedCookie();
System.out.println("Connected to " + m_strServerName + " at " + m_nPort + " as " + m_strNativeUsername);
System.out.println("Cookie = " + m_strCookie);
}
public void testAddPrincipalTrustMatrix(int pid, int tsid, int flag) throws TEAgentException {
TrustedServerAdmin tsAdmin = new TrustedServerAdmin();
tsAdmin.attachConnection(m_conn);
// Add a PrincipalTrustMatrix
PrincipalTrustMatrix matrix = new PrincipalTrustMatrix(pid, tsid, flag);
matrix = tsAdmin.addPrincipalTrustMatrix(matrix);
System.out.println("PrincipalTrustMatrix was added to the server:");
System.out.println(matrix.toString());
// Add several PrincipalTrustMatrices
PrincipalTrustMatrix[] matrices = new PrincipalTrustMatrix[2];
matrices[0] = new PrincipalTrustMatrix(1, 1912, PrincipalTrustMatrix.FLAG_EXPOSE);
matrices[1] = new PrincipalTrustMatrix(3001, 1912, PrincipalTrustMatrix.FLAG_RESTRICT);
matrices = tsAdmin.addPrincipalTrustMatrix(matrices);
System.out.println("PrincipalTrustMatrices were added to the server:");
for(int i=0; i<matrices.length; i++) {
PrincipalTrustMatrix matrix2 = (PrincipalTrustMatrix)matrices[i];
System.out.println( i + " : " + matrix2.toString());
}
}
public void disconnect() throws TEAgentException {
// Close connection
m_conn.close();
System.out.println("Disconnected from " + m_strServerName);
}
public static void main(String[] args) {
try {
Java_TrustedServerAdmin_Add_PrincipalTrustMatrix java_test = new Java_TrustedServerAdmin_Add_PrincipalTrustMatrix();
// Native user login
java_test.connect_native("localhost", 8888, "admin", "password1A");
// Test adding PrincipalTrustMatrix
java_test.testAddPrincipalTrustMatrix(1001, 1912, PrincipalTrustMatrix.FLAG_EXPOSE);
// Disconnect
java_test.disconnect();
}
catch (TEAgentException te) {
te.printStackTrace();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**************************************************************************************
Connected to localhost at 8888 as admin
Cookie = SFDiu7irK4wfKKyxeG0CqTiWOu8=
PrincipalTrustMatrix was added to the server:
PrincipalTrustMatrix:
<ID: 1005 >
<Principal ID: 1001 >
<Trusted Server ID: 1912 >
<Flag: 2 >
PrincipalTrustMatrices were added to the server:
0 : PrincipalTrustMatrix:
<ID: 1006 >
<Principal ID: 1 >
<Trusted Server ID: 1912 >
<Flag: 2 >
1 : PrincipalTrustMatrix:
<ID: 1007 >
<Principal ID: 3001 >
<Trusted Server ID: 1912 >
<Flag: 1 >
Disconnected from localhost
**************************************************************************************/