use of com.orientechnologies.orient.server.network.protocol.OBeforeDatabaseOpenNetworkEventListener in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method openDatabase.
protected void openDatabase(OClientConnection connection) throws IOException {
setDataCommandInfo(connection, "Open database");
readConnectionData(connection);
final String dbURL = channel.readString();
String dbType = ODatabaseDocument.TYPE;
if (connection.getData().protocolVersion <= OChannelBinaryProtocol.PROTOCOL_VERSION_32)
// READ DB-TYPE FROM THE CLIENT. NOT USED ANYMORE
dbType = channel.readString();
final String user = channel.readString();
final String passwd = channel.readString();
for (OBeforeDatabaseOpenNetworkEventListener l : listener.getBeforeDatabaseOpenNetworkEventListener()) l.onBeforeDatabaseOpen(dbURL);
try {
connection.setDatabase((ODatabaseDocumentTx) server.openDatabase(dbURL, user, passwd, connection.getData()));
} catch (OException e) {
server.getClientConnectionManager().disconnect(connection);
throw e;
}
byte[] token = null;
if (Boolean.TRUE.equals(connection.getTokenBased())) {
token = server.getTokenHandler().getSignedBinaryToken(connection.getDatabase(), connection.getDatabase().getUser(), connection.getData());
// TODO: do not use the parse split getSignedBinaryToken in two methods.
getServer().getClientConnectionManager().connect(this, connection, token, server.getTokenHandler());
}
if (connection.getDatabase().getStorage() instanceof OStorageProxy && !loadUserFromSchema(connection, user, passwd)) {
sendErrorOrDropConnection(connection, clientTxId, new OSecurityAccessException(connection.getDatabase().getName(), "User or password not valid for database: '" + connection.getDatabase().getName() + "'"));
} else {
beginResponse();
try {
sendOk(connection, clientTxId);
channel.writeInt(connection.getId());
if (connection.getData().protocolVersion > OChannelBinaryProtocol.PROTOCOL_VERSION_26) {
if (Boolean.TRUE.equals(connection.getTokenBased())) {
channel.writeBytes(token);
} else
channel.writeBytes(OCommonConst.EMPTY_BYTE_ARRAY);
}
sendDatabaseInformation(connection);
final OServerPlugin plugin = server.getPlugin("cluster");
ODocument distributedCfg = null;
if (plugin != null && plugin instanceof ODistributedServerManager) {
distributedCfg = ((ODistributedServerManager) plugin).getClusterConfiguration();
final ODistributedConfiguration dbCfg = ((ODistributedServerManager) plugin).getDatabaseConfiguration(connection.getDatabase().getName());
if (dbCfg != null) {
// ENHANCE SERVER CFG WITH DATABASE CFG
distributedCfg.field("database", dbCfg.getDocument(), OType.EMBEDDED);
}
}
channel.writeBytes(distributedCfg != null ? getRecordBytes(connection, distributedCfg) : null);
if (connection.getData().protocolVersion >= 14)
channel.writeString(OConstants.getVersion());
} finally {
endResponse(connection);
}
}
}
Aggregations