use of com.orientechnologies.orient.core.metadata.security.OToken in project orientdb by orientechnologies.
the class OTokenHandlerImplTest method testWebTokenCreationValidation.
@Test
@Ignore
public void testWebTokenCreationValidation() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OTokenHandlerImplTest.class.getSimpleName());
db.create();
try {
OSecurityUser original = db.getUser();
OTokenHandlerImpl handler = new OTokenHandlerImpl("any key".getBytes(), 60, "HmacSHA256");
byte[] token = handler.getSignedWebToken(db, original);
try {
// Make this thread wait at least 10 milliseconds before check the validity
Thread.sleep(10);
} catch (InterruptedException e) {
}
OToken tok = handler.parseWebToken(token);
assertNotNull(tok);
assertTrue(tok.getIsVerified());
OUser user = tok.getUser(db);
assertEquals(user.getName(), original.getName());
boolean boole = handler.validateToken(tok, "open", db.getName());
assertTrue(boole);
assertTrue(tok.getIsValid());
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.metadata.security.OToken in project orientdb by orientechnologies.
the class OTokenHandlerImplTest method testTokenNotRenew.
@Test
public void testTokenNotRenew() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OTokenHandlerImplTest.class.getSimpleName());
db.create();
try {
OSecurityUser original = db.getUser();
OTokenHandlerImpl handler = new OTokenHandlerImpl("any key".getBytes(), 60, "HmacSHA256");
ONetworkProtocolData data = new ONetworkProtocolData();
data.driverName = "aa";
data.driverVersion = "aa";
data.serializationImpl = "a";
data.protocolVersion = 2;
byte[] token = handler.getSignedBinaryToken(db, original, data);
OToken tok = handler.parseBinaryToken(token);
token = handler.renewIfNeeded(tok);
assertEquals(0, token.length);
} finally {
db.drop();
}
}
Aggregations