Search in sources :

Example 1 with OTokenException

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;
}
Also used : OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) OSystemException(com.orientechnologies.common.exception.OSystemException) OBinaryToken(com.orientechnologies.orient.server.binary.impl.OBinaryToken)

Example 2 with OTokenException

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);
}
Also used : OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Aggregations

OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)1 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)1 OException (com.orientechnologies.common.exception.OException)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OIOException (com.orientechnologies.common.io.OIOException)1 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)1 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)1 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)1 OBinaryToken (com.orientechnologies.orient.server.binary.impl.OBinaryToken)1 IOException (java.io.IOException)1 NamingException (javax.naming.NamingException)1