use of com.orientechnologies.orient.server.binary.impl.OBinaryToken in project orientdb by orientechnologies.
the class OBinaryTokenSerializerTest method testSerializerDeserializeToken.
@Test
public void testSerializerDeserializeToken() throws IOException {
OBinaryToken token = new OBinaryToken();
token.setDatabase("test");
token.setDatabaseType("plocal");
token.setUserRid(new ORecordId(43, 234));
OrientJwtHeader header = new OrientJwtHeader();
header.setKeyId("key");
header.setAlgorithm("HmacSHA256");
header.setType("OrientDB");
token.setHeader(header);
token.setExpiry(20L);
token.setProtocolVersion((short) 2);
token.setSerializer("ser");
token.setDriverName("aa");
token.setDriverVersion("aa");
ByteArrayOutputStream bas = new ByteArrayOutputStream();
ser.serialize(token, bas);
ByteArrayInputStream input = new ByteArrayInputStream(bas.toByteArray());
OBinaryToken tok = ser.deserialize(input);
assertEquals("test", token.getDatabase());
assertEquals("plocal", token.getDatabaseType());
ORID id = token.getUserId();
assertEquals(43, id.getClusterId());
assertEquals(20L, tok.getExpiry());
assertEquals("OrientDB", tok.getHeader().getType());
assertEquals("HmacSHA256", tok.getHeader().getAlgorithm());
assertEquals("key", tok.getHeader().getKeyId());
assertEquals((short) 2, tok.getProtocolVersion());
assertEquals("ser", tok.getSerializer());
assertEquals("aa", tok.getDriverName());
assertEquals("aa", tok.getDriverVersion());
}
use of com.orientechnologies.orient.server.binary.impl.OBinaryToken in project orientdb by orientechnologies.
the class OTokenHandlerImpl method parseBinaryToken.
public OToken parseBinaryToken(final byte[] binaryToken) {
try {
final ByteArrayInputStream bais = new ByteArrayInputStream(binaryToken);
final OBinaryToken token = deserializeBinaryToken(bais);
final int end = binaryToken.length - bais.available();
final byte[] decodedSignature = new byte[bais.available()];
bais.read(decodedSignature);
token.setIsVerified(verifyTokenSignature(token.getHeader(), binaryToken, 0, end, decodedSignature));
return token;
} catch (IOException e) {
throw OException.wrapException(new OSystemException("Error on token parsing"), e);
}
}
use of com.orientechnologies.orient.server.binary.impl.OBinaryToken in project orientdb by orientechnologies.
the class OTokenHandlerImpl method getProtocolDataFromToken.
public ONetworkProtocolData getProtocolDataFromToken(OClientConnection connection, final OToken token) {
if (token instanceof OBinaryToken) {
final OBinaryToken binary = (OBinaryToken) token;
final ONetworkProtocolData data = new ONetworkProtocolData();
// data.clientId = binary.get;
data.protocolVersion = binary.getProtocolVersion();
data.serializationImpl = binary.getSerializer();
data.driverName = binary.getDriverName();
data.driverVersion = binary.getDriverVersion();
data.serverUser = binary.isServerUser();
data.serverUsername = binary.getUserName();
data.serverUsername = binary.getUserName();
data.supportsPushMessages = connection.getData().supportsPushMessages;
data.collectStats = connection.getData().collectStats;
return data;
}
return null;
}
Aggregations