Search in sources :

Example 1 with OTokenSecurityException

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));
        }
    }
}
Also used : OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 2 with OTokenSecurityException

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

Example 3 with OTokenSecurityException

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);
    }
}
Also used : OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OSystemException(com.orientechnologies.common.exception.OSystemException) OToken(com.orientechnologies.orient.core.metadata.security.OToken) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OSystemException(com.orientechnologies.common.exception.OSystemException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)

Example 4 with OTokenSecurityException

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;
}
Also used : OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OToken(com.orientechnologies.orient.core.metadata.security.OToken) OException(com.orientechnologies.common.exception.OException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) IOException(java.io.IOException)

Aggregations

OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)4 OException (com.orientechnologies.common.exception.OException)3 IOException (java.io.IOException)3 OToken (com.orientechnologies.orient.core.metadata.security.OToken)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)1 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OIOException (com.orientechnologies.common.io.OIOException)1 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)1 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)1 NamingException (javax.naming.NamingException)1