Search in sources :

Example 1 with ONetworkProtocolData

use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData in project orientdb by orientechnologies.

the class OTokenHandlerImplTest method testTokenRenew.

@Test
public void testTokenRenew() {
    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);
        tok.setExpiry(System.currentTimeMillis() + (handler.getSessionInMills() / 2) - 1);
        token = handler.renewIfNeeded(tok);
        assertTrue(token.length != 0);
    } finally {
        db.drop();
    }
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) OToken(com.orientechnologies.orient.core.metadata.security.OToken) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) Test(org.junit.Test)

Example 2 with ONetworkProtocolData

use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData in project orientdb by orientechnologies.

the class OTokenHandlerImplTest method testBinartTokenCreationValidation.

@Test
public void testBinartTokenCreationValidation() 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");
        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);
        assertNotNull(tok);
        assertTrue(tok.getIsVerified());
        OUser user = tok.getUser(db);
        assertEquals(user.getName(), original.getName());
        boolean boole = handler.validateBinaryToken(tok);
        assertTrue(boole);
        assertTrue(tok.getIsValid());
    } finally {
        db.drop();
    }
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) OToken(com.orientechnologies.orient.core.metadata.security.OToken) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) Test(org.junit.Test)

Example 3 with ONetworkProtocolData

use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData in project orientdb by orientechnologies.

the class OServerInfo method getConnections.

public static void getConnections(final OServer server, final OJSONWriter json, final String databaseName) throws IOException {
    final DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    json.beginCollection(1, true, "connections");
    final List<OClientConnection> conns = server.getClientConnectionManager().getConnections();
    for (OClientConnection c : conns) {
        final ONetworkProtocolData data = c.getData();
        final OClientConnectionStats stats = c.getStats();
        if (databaseName != null && !databaseName.equals((stats.lastDatabase)))
            // SKIP IT
            continue;
        final String lastCommandOn;
        final String connectedOn;
        synchronized (dateTimeFormat) {
            lastCommandOn = dateTimeFormat.format(new Date(stats.lastCommandReceived));
            connectedOn = dateTimeFormat.format(new Date(c.getSince()));
        }
        String lastDatabase;
        String lastUser;
        if (stats.lastDatabase != null && stats.lastUser != null) {
            lastDatabase = stats.lastDatabase;
            lastUser = stats.lastUser;
        } else {
            lastDatabase = data.lastDatabase;
            lastUser = data.lastUser;
        }
        json.beginObject(2);
        writeField(json, 2, "connectionId", c.getId());
        writeField(json, 2, "remoteAddress", c.getProtocol().getChannel() != null ? c.getProtocol().getChannel().toString() : "Disconnected");
        writeField(json, 2, "db", lastDatabase != null ? lastDatabase : "-");
        writeField(json, 2, "user", lastUser != null ? lastUser : "-");
        writeField(json, 2, "totalRequests", stats.totalRequests);
        writeField(json, 2, "commandInfo", data.commandInfo);
        writeField(json, 2, "commandDetail", data.commandDetail);
        writeField(json, 2, "lastCommandOn", lastCommandOn);
        writeField(json, 2, "lastCommandInfo", stats.lastCommandInfo);
        writeField(json, 2, "lastCommandDetail", stats.lastCommandDetail);
        writeField(json, 2, "lastExecutionTime", stats.lastCommandExecutionTime);
        writeField(json, 2, "totalWorkingTime", stats.totalCommandExecutionTime);
        writeField(json, 2, "connectedOn", connectedOn);
        writeField(json, 2, "protocol", c.getProtocol().getType());
        writeField(json, 2, "sessionId", data.sessionId);
        writeField(json, 2, "clientId", data.clientId);
        final StringBuilder driver = new StringBuilder(128);
        if (data.driverName != null) {
            driver.append(data.driverName);
            driver.append(" v");
            driver.append(data.driverVersion);
            driver.append(" Protocol v");
            driver.append(data.protocolVersion);
        }
        writeField(json, 2, "driver", driver.toString());
        json.endObject(2);
    }
    json.endCollection(1, false);
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with ONetworkProtocolData

use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData 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)

Example 5 with ONetworkProtocolData

use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData 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();
    }
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) OToken(com.orientechnologies.orient.core.metadata.security.OToken) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) Test(org.junit.Test)

Aggregations

ONetworkProtocolData (com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 OSecurityUser (com.orientechnologies.orient.core.metadata.security.OSecurityUser)3 OToken (com.orientechnologies.orient.core.metadata.security.OToken)3 Test (org.junit.Test)3 OUser (com.orientechnologies.orient.core.metadata.security.OUser)1 OBinaryToken (com.orientechnologies.orient.server.binary.impl.OBinaryToken)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1