use of com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException in project orientdb by orientechnologies.
the class OClientConnection method init.
public void init(final OServer server) {
if (database == null) {
setData(server.getTokenHandler().getProtocolDataFromToken(this, token));
if (data == null)
throw new OTokenSecurityException("missing in token data");
final String db = token.getDatabase();
final String type = token.getDatabaseType();
if (db != null && type != null) {
if (data.serverUser) {
setDatabase((ODatabaseDocumentTx) server.openDatabase(type + ":" + db, token.getUserName(), null, data, true));
} else
setDatabase((ODatabaseDocumentTx) server.openDatabase(type + ":" + db, token));
}
}
}
use of com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException in project orientdb by orientechnologies.
the class OStorageRemote method baseNetworkOperation.
public <T> T baseNetworkOperation(final OStorageRemoteOperation<T> operation, final String errorMessage, int retry) {
OStorageRemoteSession session = getCurrentSession();
if (session.commandExecuting)
throw new ODatabaseException("Cannot execute the request because an asynchronous operation is in progress. Please use a different connection");
String serverUrl = null;
do {
OChannelBinaryAsynchClient network = null;
if (serverUrl == null)
serverUrl = getNextAvailableServerURL(false, session);
do {
try {
network = getNetwork(serverUrl);
} catch (OException e) {
serverUrl = useNewServerURL(serverUrl);
if (serverUrl == null)
throw e;
}
} while (network == null);
try {
// In case i do not have a token or i'm switching between server i've to execute a open operation.
OStorageRemoteNodeSession nodeSession = session.getServerSession(network.getServerURL());
if (nodeSession == null || !nodeSession.isValid()) {
openRemoteDatabase(network);
if (!network.tryLock()) {
connectionManager.release(network);
continue;
}
}
return operation.execute(network, session);
} catch (ODistributedRedirectException e) {
connectionManager.release(network);
OLogManager.instance().debug(this, "Redirecting the request from server '%s' to the server '%s' because %s", e.getFromServer(), e.toString(), e.getMessage());
// RECONNECT TO THE SERVER SUGGESTED IN THE EXCEPTION
serverUrl = e.getToServerAddress();
} catch (OModificationOperationProhibitedException mope) {
connectionManager.release(network);
handleDBFreeze();
serverUrl = null;
} catch (OTokenException e) {
connectionManager.release(network);
session.removeServerSession(network.getServerURL());
if (--retry <= 0)
throw OException.wrapException(new OStorageException(errorMessage), e);
serverUrl = null;
} catch (OTokenSecurityException e) {
connectionManager.release(network);
session.removeServerSession(network.getServerURL());
if (--retry <= 0)
throw OException.wrapException(new OStorageException(errorMessage), e);
serverUrl = null;
} catch (OOfflineNodeException e) {
connectionManager.release(network);
// Remove the current url because the node is offline
synchronized (serverURLs) {
serverURLs.remove(serverUrl);
}
for (OStorageRemoteSession activeSession : sessions) {
// Not thread Safe ...
activeSession.removeServerSession(serverUrl);
}
serverUrl = null;
} catch (IOException e) {
connectionManager.release(network);
retry = handleIOException(retry, network, e);
serverUrl = null;
} catch (OIOException e) {
connectionManager.release(network);
retry = handleIOException(retry, network, e);
serverUrl = null;
} catch (OException e) {
connectionManager.release(network);
throw e;
} catch (Exception e) {
connectionManager.release(network);
throw OException.wrapException(new OStorageException(errorMessage), e);
}
} while (true);
}
use of com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException in project orientdb by orientechnologies.
the class OClientConnection method validateSession.
public void validateSession(byte[] tokenFromNetwork, OTokenHandler handler, ONetworkProtocolBinary protocol) {
if (tokenFromNetwork == null || tokenFromNetwork.length == 0) {
if (!protocols.contains(protocol))
throw new OTokenSecurityException("No valid session found, provide a token");
} else {
//IF the byte from the network are the same of the one i have a don't check them
if (tokenBytes != null && tokenBytes.length > 0) {
if (// SAME SESSION AND TOKEN DO
tokenBytes.equals(tokenFromNetwork))
return;
}
OToken token = null;
try {
if (tokenFromNetwork != null)
token = handler.parseBinaryToken(tokenFromNetwork);
} catch (Exception e) {
throw OException.wrapException(new OSystemException("Error on token parse"), e);
}
if (token == null || !token.getIsVerified()) {
cleanSession();
protocol.getServer().getClientConnectionManager().disconnect(this);
throw new OTokenSecurityException("The token provided is not a valid token, signature does not match");
}
if (!handler.validateBinaryToken(token)) {
cleanSession();
protocol.getServer().getClientConnectionManager().disconnect(this);
throw new OTokenSecurityException("The token provided is expired");
}
if (tokenBased == null) {
tokenBased = Boolean.TRUE;
}
if (!Arrays.equals(this.tokenBytes, tokenFromNetwork))
cleanSession();
this.tokenBytes = tokenFromNetwork;
this.token = token;
protocols.add(protocol);
}
}
use of com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException in project orientdb by orientechnologies.
the class OClientConnectionManager method connect.
/**
* Create a connection.
*
* @param iProtocol
* protocol which will be used by connection
* @return new connection
* @throws IOException
*/
public OClientConnection connect(final ONetworkProtocol iProtocol, final OClientConnection connection, final byte[] tokenBytes, final OTokenHandler handler) throws IOException {
final OToken token;
try {
token = handler.parseBinaryToken(tokenBytes);
} catch (Exception e) {
throw OException.wrapException(new OTokenSecurityException("Error on token parsing"), e);
}
OClientSessions session;
synchronized (sessions) {
session = new OClientSessions(tokenBytes, token);
sessions.put(new OHashToken(tokenBytes), session);
}
connection.setTokenBytes(tokenBytes);
connection.setTokenBased(true);
connection.setToken(token);
session.addConnection(connection);
OLogManager.instance().config(this, "Remote client connected from: " + connection);
OServerPluginHelper.invokeHandlerCallbackOnClientConnection(iProtocol.getServer(), connection);
return connection;
}
Aggregations