Skip to main content

Creating a Connection

Authenticator availability

Native (SRP) and Certificate (X.509) are the self-authenticating principal types every kS provides. Directory authenticators (the LDAP/Kerberos lineages, including the Windows and NIS samples) are build-dependent and not present in every shipped kS.

To create a connection to a kS


Sample_Admin_Connect.java

The following code sample illustrates how to create a connection to a remote engine (rE) or the kS using native credentials, a certificate, or an active Windows session.

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teagent.TEAgentException;
import com.eruces.teagent.TEAgentSSLMConnection;

public class Sample_Admin_Connect {

public static void disconnect(TEAgentConnection conn) {

try {
String serv = conn.getServerName();
int port = conn.getServerPort();

conn.close();
System.out.println("Disconnected from " + serv + ":" + port + ".");
}
catch (Exception e) {
e.printStackTrace();
}
}

public static TEAgentConnection nativeConnect(String user, String pass, String serv, int port) {

TEAgentConnection conn = null;

try {
conn = TEAgentConnectionFactory.getInstance(TEAgentConnectionFactory.SECURE_USER_PASSWORD);

conn.open(serv, port, user, pass);
System.out.println("Connected to " + serv + ":" + port + " as " + user + ".");
}
catch (Exception e) {
e.printStackTrace();
}

return conn;
}

public static TEAgentConnection windowsConnect(String user, String pass, String serv, int port) {

TEAgentConnection conn = null;

try {
conn = TEAgentConnectionFactory.getInstance(TEAgentConnectionFactory.SECURE_USER_PASSWORD);

conn.open(serv, port, user, pass);
System.out.println("Connected to " + serv + ":" + port + " as " + user + ".");
}
catch (Exception e) {
e.printStackTrace();
}

return conn;
}

public static TEAgentConnection certificateConnect(String cert, String pass, String serv, int port) {

TEAgentSSLMConnection conn = null;

try {
conn = new TEAgentSSLMConnection();
InputStream istream = new FileInputStream(cert);

conn.open(serv, port, istream, pass);
System.out.println("Connected to " + serv + ":" + port + " with certificate \"" + cert + "\".");
}
catch (TEAgentException b) {
if (b.toString().contains("BadPaddingException")) {
System.out.println("A 'BadPaddingException' has occurred. Usually this indicates that something is wrong with the decryption key or decryption method used in the certificate.");
}
b.printStackTrace();
}
catch (FileNotFoundException e) {
System.out.println("The specified certificate file could not be found.");
e.printStackTrace();
}

return conn;
}