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();
}
}
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();
}
}
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);
}
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;
}
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();
}
}
Aggregations