use of com.orientechnologies.orient.core.metadata.security.OTokenException in project orientdb by orientechnologies.
the class OTokenHandlerImpl method renewIfNeeded.
@Override
public byte[] renewIfNeeded(final OToken token) {
if (token == null)
throw new IllegalArgumentException("Token is null");
final long curTime = System.currentTimeMillis();
if (token.getExpiry() - curTime < (sessionInMills / 2) && token.getExpiry() >= curTime) {
final long expiryMinutes = sessionInMills;
final long currTime = System.currentTimeMillis();
token.setExpiry(currTime + expiryMinutes);
try {
if (token instanceof OBinaryToken)
return serializeSignedToken((OBinaryToken) token);
else
throw new OTokenException("renew of web token not supported");
} catch (IOException e) {
throw OException.wrapException(new OSystemException("Error on token parsing"), e);
}
}
return OCommonConst.EMPTY_BYTE_ARRAY;
}
use of com.orientechnologies.orient.core.metadata.security.OTokenException 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);
}
Aggregations