use of org.neo4j.driver.v1.Session in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method transactionEnlistmentReadAfterCallingTransactionClose.
public String transactionEnlistmentReadAfterCallingTransactionClose() {
// JTA transaction is started by CMT, the following obtains a Session that is enlisted into the JTA transaction.
Session session = injectedDriver.session();
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
try {
session.run("CREATE (a:Person {name:'TRANSACTION', title:'King'})");
return nestedBean.getPerson("TRANSACTION");
} finally {
if (session.isOpen()) {
// this will be true
session.run("MATCH (a:Person) delete a");
// ignored, session is auto closed when the transaction ends.
session.close();
}
}
}
use of org.neo4j.driver.v1.Session in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addPersonClassInstanceInjection.
public String addPersonClassInstanceInjection() {
Session session = injectedDriver.session();
try {
session.run("CREATE (a:Person {name:'CDI', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'CDI' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
use of org.neo4j.driver.v1.Session in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addPerson.
public String addPerson() {
Session session = driver.session();
try {
session.run("CREATE (a:Person {name:'Arthur', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
use of org.neo4j.driver.v1.Session in project xipki by xipki.
the class IaikP11Slot method generateKeyPair.
private P11Identity generateKeyPair(long mech, PrivateKey privateKey, PublicKey publicKey) throws P11TokenException {
final String label = toString(privateKey.getLabel());
byte[] id = null;
try {
KeyPair keypair;
Session session = borrowWritableSession();
try {
if (labelExists(session, label)) {
throw new IllegalArgumentException("label " + label + " exists, please specify another one");
}
id = generateKeyId(session);
privateKey.getId().setByteArrayValue(id);
publicKey.getId().setByteArrayValue(id);
try {
keypair = session.generateKeyPair(Mechanism.get(mech), publicKey, privateKey);
} catch (TokenException ex) {
throw new P11TokenException("could not generate keypair " + Pkcs11Functions.mechanismCodeToString(mech), ex);
}
P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label);
P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);
java.security.PublicKey jcePublicKey;
try {
jcePublicKey = generatePublicKey(keypair.getPublicKey());
} catch (XiSecurityException ex) {
throw new P11TokenException("could not generate public key " + objId, ex);
}
PrivateKey privateKey2 = getPrivateKeyObject(session, id, label.toCharArray());
if (privateKey2 == null) {
throw new P11TokenException("could not read the generated private key");
}
return new IaikP11Identity(this, entityId, privateKey2, jcePublicKey, null);
} finally {
returnWritableSession(session);
}
} catch (P11TokenException | RuntimeException ex) {
try {
removeObjects(id, label);
} catch (Throwable th) {
LogUtil.error(LOG, th, "could not remove objects");
}
throw ex;
}
}
use of org.neo4j.driver.v1.Session in project xipki by xipki.
the class IaikP11Slot method digestKey.
byte[] digestKey(long mechanism, IaikP11Identity identity) throws P11TokenException {
ParamUtil.requireNonNull("identity", identity);
assertMechanismSupported(mechanism);
Key signingKey = identity.getSigningKey();
if (!(signingKey instanceof SecretKey)) {
throw new P11TokenException("digestSecretKey could not be applied to non-SecretKey");
}
if (LOG.isTraceEnabled()) {
LOG.debug("digest (init, digestKey, then finish)\n{}", signingKey);
}
int digestLen;
if (PKCS11Constants.CKM_SHA_1 == mechanism) {
digestLen = 20;
} else if (PKCS11Constants.CKM_SHA224 == mechanism || PKCS11Constants.CKM_SHA3_224 == mechanism) {
digestLen = 28;
} else if (PKCS11Constants.CKM_SHA256 == mechanism || PKCS11Constants.CKM_SHA3_256 == mechanism) {
digestLen = 32;
} else if (PKCS11Constants.CKM_SHA384 == mechanism || PKCS11Constants.CKM_SHA3_384 == mechanism) {
digestLen = 48;
} else if (PKCS11Constants.CKM_SHA512 == mechanism || PKCS11Constants.CKM_SHA3_512 == mechanism) {
digestLen = 64;
} else {
throw new P11TokenException("unsupported mechnism " + mechanism);
}
ConcurrentBagEntry<Session> session0 = borrowSession();
try {
Session session = session0.value();
session.digestInit(Mechanism.get(mechanism));
session.digestKey((SecretKey) signingKey);
byte[] digest = new byte[digestLen];
session.digestFinal(digest, 0, digestLen);
return digest;
} catch (TokenException ex) {
throw new P11TokenException(ex);
} finally {
sessions.requite(session0);
}
}
Aggregations