Search in sources :

Example 71 with Session

use of iaik.pkcs.pkcs11.Session in project neo4j by neo4j.

the class ProcedureTest method calls_procedures_with_simple_input_type_returning_record_with_primitive_fields.

@Test
public void calls_procedures_with_simple_input_type_returning_record_with_primitive_fields() {
    try (Driver driver = GraphDatabase.driver(graphDb.boltURI(), configuration());
        Session session = driver.session()) {
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput11('string')").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput12(42)").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput13(42)").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput14(4.2)").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput15(true)").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput16(false)").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput17({foo:'bar'})").single()).isNotNull();
        assertThat(session.run("CALL " + procedureNamespace + ".simpleInput21()").single()).isNotNull();
    }
}
Also used : Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 72 with Session

use of iaik.pkcs.pkcs11.Session in project intellij-community by JetBrains.

the class Basic method main.

public static void main(String[] args) {
    String hostname = "127.0.0.1";
    String username = "joe";
    String password = "joespass";
    try {
        /* Create a connection instance */
        Connection conn = new Connection(hostname);
        /* Now connect */
        conn.connect();
        /* Authenticate.
			 * If you get an IOException saying something like
			 * "Authentication method password not supported by the server at this stage."
			 * then please check the FAQ.
			 */
        boolean isAuthenticated = conn.authenticateWithPassword(username, password);
        if (isAuthenticated == false)
            throw new IOException("Authentication failed.");
        /* Create a session */
        Session sess = conn.openSession();
        sess.execCommand("uname -a && date && uptime && who");
        System.out.println("Here is some information about the remote host:");
        /* 
			 * This basic example does not handle stderr, which is sometimes dangerous
			 * (please read the FAQ).
			 */
        InputStream stdout = new StreamGobbler(sess.getStdout());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
        /* Show exit status, if available (otherwise "null") */
        System.out.println("ExitCode: " + sess.getExitStatus());
        /* Close this session */
        sess.close();
        /* Close the connection */
        conn.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(2);
    }
}
Also used : StreamGobbler(com.trilead.ssh2.StreamGobbler) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Connection(com.trilead.ssh2.Connection) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Session(com.trilead.ssh2.Session)

Example 73 with Session

use of iaik.pkcs.pkcs11.Session in project intellij-community by JetBrains.

the class PublicKeyAuthentication method main.

public static void main(String[] args) {
    String hostname = "127.0.0.1";
    String username = "joe";
    // or "~/.ssh/id_dsa"
    File keyfile = new File("~/.ssh/id_rsa");
    // will be ignored if not needed
    String keyfilePass = "joespass";
    try {
        /* Create a connection instance */
        Connection conn = new Connection(hostname);
        /* Now connect */
        conn.connect();
        /* Authenticate */
        boolean isAuthenticated = conn.authenticateWithPublicKey(username, keyfile, keyfilePass);
        if (isAuthenticated == false)
            throw new IOException("Authentication failed.");
        /* Create a session */
        Session sess = conn.openSession();
        sess.execCommand("uname -a && date && uptime && who");
        InputStream stdout = new StreamGobbler(sess.getStdout());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        System.out.println("Here is some information about the remote host:");
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
        /* Close this session */
        sess.close();
        /* Close the connection */
        conn.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(2);
    }
}
Also used : StreamGobbler(com.trilead.ssh2.StreamGobbler) Connection(com.trilead.ssh2.Connection) Session(com.trilead.ssh2.Session)

Example 74 with Session

use of iaik.pkcs.pkcs11.Session in project intellij-community by JetBrains.

the class UsingKnownHosts method main.

public static void main(String[] args) throws IOException {
    String hostname = "somehost";
    String username = "joe";
    String password = "joespass";
    File knownHosts = new File("~/.ssh/known_hosts");
    try {
        if (knownHosts.exists())
            database.addHostkeys(knownHosts);
        /* Create a connection instance */
        Connection conn = new Connection(hostname);
        /* Now connect and use the SimpleVerifier */
        conn.connect(new SimpleVerifier(database));
        /* Authenticate */
        boolean isAuthenticated = conn.authenticateWithPassword(username, password);
        if (isAuthenticated == false)
            throw new IOException("Authentication failed.");
        /* Create a session */
        Session sess = conn.openSession();
        sess.execCommand("uname -a && date && uptime && who");
        InputStream stdout = new StreamGobbler(sess.getStdout());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        System.out.println("Here is some information about the remote host:");
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
        /* Close this session */
        sess.close();
        /* Close the connection */
        conn.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(2);
    }
}
Also used : StreamGobbler(com.trilead.ssh2.StreamGobbler) Connection(com.trilead.ssh2.Connection) Session(com.trilead.ssh2.Session)

Example 75 with Session

use of iaik.pkcs.pkcs11.Session in project ACS by ACS-Community.

the class Executor method remoteDownAllPortable.

/**
	 * Shuts down all ssh-sessions and -connections that may still be active.
	 */
private static void remoteDownAllPortable() {
    for (Session sess : sessions) {
        try {
            sess.close();
            log.fine("closed " + sess);
        } catch (Exception exc) {
            log.fine("could not close " + sess);
        }
    }
    for (Connection conn : connections) {
        try {
            conn.close();
            log.fine("closed " + conn);
        } catch (Exception exc) {
            log.fine("could not close " + conn);
        }
    }
}
Also used : Connection(com.trilead.ssh2.Connection) IOException(java.io.IOException) OrbInitException(alma.acs.commandcenter.meta.Firestarter.OrbInitException) AcsJException(alma.acs.exceptions.AcsJException) Session(com.trilead.ssh2.Session)

Aggregations

Session (com.trilead.ssh2.Session)42 Session (org.neo4j.driver.v1.Session)38 Connection (com.trilead.ssh2.Connection)32 IOException (java.io.IOException)29 Test (org.junit.Test)29 InputStream (java.io.InputStream)27 Driver (org.neo4j.driver.v1.Driver)27 StatementResult (org.neo4j.driver.v1.StatementResult)20 TokenException (iaik.pkcs.pkcs11.TokenException)15 P11TokenException (org.xipki.security.exception.P11TokenException)15 Record (org.neo4j.driver.v1.Record)12 Session (iaik.pkcs.pkcs11.Session)10 SecretKey (iaik.pkcs.pkcs11.objects.SecretKey)10 ValuedSecretKey (iaik.pkcs.pkcs11.objects.ValuedSecretKey)10 DSAPrivateKey (iaik.pkcs.pkcs11.objects.DSAPrivateKey)9 ECPrivateKey (iaik.pkcs.pkcs11.objects.ECPrivateKey)9 PrivateKey (iaik.pkcs.pkcs11.objects.PrivateKey)9 RSAPrivateKey (iaik.pkcs.pkcs11.objects.RSAPrivateKey)9 SM2PrivateKey (iaik.pkcs.pkcs11.objects.SM2PrivateKey)9 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)9