Search in sources :

Example 76 with Session

use of com.google.spanner.v1.Session in project xipki by xipki.

the class IaikP11Slot method sign.

byte[] sign(long mechanism, P11Params parameters, byte[] content, IaikP11Identity identity) throws P11TokenException {
    ParamUtil.requireNonNull("content", content);
    assertMechanismSupported(mechanism);
    int len = content.length;
    int expectedSignatureLen;
    if (mechanism == PKCS11Constants.CKM_SHA_1_HMAC) {
        expectedSignatureLen = 20;
    } else if (mechanism == PKCS11Constants.CKM_SHA224_HMAC || mechanism == PKCS11Constants.CKM_SHA3_224) {
        expectedSignatureLen = 28;
    } else if (mechanism == PKCS11Constants.CKM_SHA256_HMAC || mechanism == PKCS11Constants.CKM_SHA3_256) {
        expectedSignatureLen = 32;
    } else if (mechanism == PKCS11Constants.CKM_SHA384_HMAC || mechanism == PKCS11Constants.CKM_SHA3_384) {
        expectedSignatureLen = 48;
    } else if (mechanism == PKCS11Constants.CKM_SHA512_HMAC || mechanism == PKCS11Constants.CKM_SHA3_512) {
        expectedSignatureLen = 64;
    } else if (mechanism == PKCS11Constants.CKM_VENDOR_SM2 || mechanism == PKCS11Constants.CKM_VENDOR_SM2_SM3) {
        expectedSignatureLen = 32;
    } else {
        expectedSignatureLen = identity.getExpectedSignatureLen();
    }
    ConcurrentBagEntry<Session> session0 = borrowSession();
    try {
        Session session = session0.value();
        if (len <= maxMessageSize) {
            return singleSign(session, mechanism, parameters, content, identity);
        }
        Key signingKey = identity.getSigningKey();
        Mechanism mechanismObj = getMechanism(mechanism, parameters);
        if (LOG.isTraceEnabled()) {
            LOG.debug("sign (init, update, then finish) with private key:\n{}", signingKey);
        }
        session.signInit(mechanismObj, signingKey);
        for (int i = 0; i < len; i += maxMessageSize) {
            int blockLen = Math.min(maxMessageSize, len - i);
            // byte[] block = new byte[blockLen];
            // System.arraycopy(content, i, block, 0, blockLen);
            session.signUpdate(content, i, blockLen);
        }
        return session.signFinal(expectedSignatureLen);
    } catch (TokenException ex) {
        throw new P11TokenException(ex);
    } finally {
        sessions.requite(session0);
    }
}
Also used : P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) RSAPrivateKey(iaik.pkcs.pkcs11.objects.RSAPrivateKey) ECPrivateKey(iaik.pkcs.pkcs11.objects.ECPrivateKey) SM2PrivateKey(iaik.pkcs.pkcs11.objects.SM2PrivateKey) ValuedSecretKey(iaik.pkcs.pkcs11.objects.ValuedSecretKey) Key(iaik.pkcs.pkcs11.objects.Key) DSAPublicKey(iaik.pkcs.pkcs11.objects.DSAPublicKey) RSAPublicKey(iaik.pkcs.pkcs11.objects.RSAPublicKey) SM2PublicKey(iaik.pkcs.pkcs11.objects.SM2PublicKey) ECPublicKey(iaik.pkcs.pkcs11.objects.ECPublicKey) PrivateKey(iaik.pkcs.pkcs11.objects.PrivateKey) DSAPrivateKey(iaik.pkcs.pkcs11.objects.DSAPrivateKey) PublicKey(iaik.pkcs.pkcs11.objects.PublicKey) SecretKey(iaik.pkcs.pkcs11.objects.SecretKey) Mechanism(iaik.pkcs.pkcs11.Mechanism) Session(iaik.pkcs.pkcs11.Session)

Example 77 with Session

use of com.google.spanner.v1.Session in project xipki by xipki.

the class IaikP11Slot method openSession.

private Session openSession(boolean rwSession) throws P11TokenException {
    Session session;
    try {
        session = slot.getToken().openSession(Token.SessionType.SERIAL_SESSION, rwSession, null, null);
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }
    countSessions.incrementAndGet();
    return session;
}
Also used : P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) Session(iaik.pkcs.pkcs11.Session)

Example 78 with Session

use of com.google.spanner.v1.Session in project rdf2neo by Rothamsted.

the class CypherHandlersIT method testRelations.

/**
 * Tests {@link CyRelationLoadingHandler} to see if relations are mapped from RDF and loaded into Neo4J.
 */
@Test
public void testRelations() throws Exception {
    try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
        CyRelationLoadingHandler handler = new CyRelationLoadingHandler();
        RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
        Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver)) {
        handler.setRdfDataManager(rdfMgr);
        handler.setNeo4jDataManager(neoMgr);
        handler.setRelationTypesSparql(RdfDataManagerTest.SPARQL_REL_TYPES);
        handler.setRelationPropsSparql(RdfDataManagerTest.SPARQL_REL_PROPS);
        Set<QuerySolution> relSparqlRows = new HashSet<>();
        Dataset dataSet = rdfMgr.getDataSet();
        Txn.executeRead(dataSet, () -> SparqlUtils.select(RdfDataManagerTest.SPARQL_REL_TYPES, rdfMgr.getDataSet().getDefaultModel()).forEachRemaining(row -> relSparqlRows.add(row)));
        handler.accept(relSparqlRows);
        Session session = neoDriver.session(AccessMode.READ);
        StatementResult cursor = session.run("MATCH ()-[r]->() RETURN COUNT ( r ) AS ct");
        Assert.assertEquals("Wrong count for relations", 3, cursor.next().get("ct").asLong());
        cursor = session.run("MATCH p = (:TestNode{ iri:$iri1 })-[:relatedTo]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:1"), "iri2", iri("ex:2")));
        Assert.assertEquals("Wrong count for {1 relatedTo 2}!", 1, cursor.next().get("ct").asLong());
        cursor = session.run("MATCH p = (:SuperTestNode{ iri:$iri1 })-[:derivedFrom]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:3"), "iri2", iri("ex:1")));
        Assert.assertEquals("Wrong count for {3 derivedFrom 1}!", 1, cursor.next().get("ct").asLong());
        cursor = session.run("MATCH (:TestNode{ iri:$iri1 })-[r:relatedTo]->(:AdditionalLabel{ iri:$iri2 }) RETURN r.note AS note", parameters("iri1", iri("ex:2"), "iri2", iri("ex:3")));
        assertTrue("{2 relatedTo 3} not found!", cursor.hasNext());
        Set<String> values = cursor.next().get("note").asList().stream().map(v -> (String) v).collect(Collectors.toSet());
        Set<String> refValues = new HashSet<>(Arrays.asList(new String[] { "Reified Relation", "Another Note" }));
        assertTrue("reified relation, wrong property value for 'note'!", Sets.difference(values, refValues).isEmpty());
    }
}
Also used : SparqlUtils(info.marcobrandizi.rdfutils.jena.SparqlUtils) Arrays(java.util.Arrays) Driver(org.neo4j.driver.v1.Driver) BeforeClass(org.junit.BeforeClass) AccessMode(org.neo4j.driver.v1.AccessMode) LoggerFactory(org.slf4j.LoggerFactory) HashSet(java.util.HashSet) QuerySolution(org.apache.jena.query.QuerySolution) Session(org.neo4j.driver.v1.Session) Txn(org.apache.jena.system.Txn) Values.parameters(org.neo4j.driver.v1.Values.parameters) Resource(org.apache.jena.rdf.model.Resource) Map(java.util.Map) GraphDatabase(org.neo4j.driver.v1.GraphDatabase) NamespaceUtils.iri(info.marcobrandizi.rdfutils.namespaces.NamespaceUtils.iri) Dataset(org.apache.jena.query.Dataset) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) AuthTokens(org.neo4j.driver.v1.AuthTokens) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Stream(java.util.stream.Stream) StatementResult(org.neo4j.driver.v1.StatementResult) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) StatementResult(org.neo4j.driver.v1.StatementResult) Dataset(org.apache.jena.query.Dataset) Driver(org.neo4j.driver.v1.Driver) QuerySolution(org.apache.jena.query.QuerySolution) HashSet(java.util.HashSet) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 79 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method translating.

@Test
public void translating() {
    Config config = Config.build().withTranslation(TranslatorFlavor.gremlinServer()).toConfig();
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config);
    try (Session session = driver.session()) {
        StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count");
        int count = result.single().get("count").asInt();
        assertThat(count).isEqualTo(4);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Config(org.opencypher.Config) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 80 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method withParameter.

@Test
public void withParameter() {
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
    try (Session session = driver.session()) {
        StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.message = $message " + "RETURN a.message", parameters("message", "Hello"));
        String message = result.single().get(0).asString();
        assertThat(message).isEqualTo("Hello");
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Aggregations

Session (com.trilead.ssh2.Session)43 Session (org.neo4j.driver.v1.Session)38 Connection (com.trilead.ssh2.Connection)32 IOException (java.io.IOException)30 Test (org.junit.Test)29 InputStream (java.io.InputStream)28 Driver (org.neo4j.driver.v1.Driver)27 StatementResult (org.neo4j.driver.v1.StatementResult)20 Record (org.neo4j.driver.v1.Record)12 Session (iaik.pkcs.pkcs11.Session)10 TokenException (iaik.pkcs.pkcs11.TokenException)10 P11TokenException (org.xipki.security.exception.P11TokenException)10 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (ch.ethz.ssh2.Session)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 HttpException (org.apache.commons.httpclient.HttpException)8 Transaction (org.neo4j.driver.v1.Transaction)7 SCPClient (com.trilead.ssh2.SCPClient)6