Search in sources :

Example 6 with OBinaryToken

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ORID(com.orientechnologies.orient.core.id.ORID) OBinaryToken(com.orientechnologies.orient.server.binary.impl.OBinaryToken) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.junit.Test)

Example 7 with OBinaryToken

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);
    }
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OBinaryToken(com.orientechnologies.orient.server.binary.impl.OBinaryToken)

Example 8 with OBinaryToken

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;
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) OBinaryToken(com.orientechnologies.orient.server.binary.impl.OBinaryToken)

Aggregations

OBinaryToken (com.orientechnologies.orient.server.binary.impl.OBinaryToken)8 OSystemException (com.orientechnologies.common.exception.OSystemException)3 ORID (com.orientechnologies.orient.core.id.ORID)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Test (org.junit.Test)3 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)2 OException (com.orientechnologies.common.exception.OException)1 ONetworkProtocolData (com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData)1 DataInputStream (java.io.DataInputStream)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1