Search in sources :

Example 1 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class ORecordSerializerBinaryDebug method deserializeDebug.

public ORecordSerializationDebug deserializeDebug(final byte[] iSource, ODatabaseDocumentInternal db) {
    ORecordSerializationDebug debugInfo = new ORecordSerializationDebug();
    OImmutableSchema schema = ((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot();
    BytesContainer bytes = new BytesContainer(iSource);
    if (bytes.bytes[0] != 0)
        throw new OSystemException("Unsupported binary serialization version");
    bytes.skip(1);
    try {
        final String className = readString(bytes);
        debugInfo.className = className;
    } catch (RuntimeException ex) {
        debugInfo.readingFailure = true;
        debugInfo.readingException = ex;
        debugInfo.failPosition = bytes.offset;
        return debugInfo;
    }
    debugInfo.properties = new ArrayList<ORecordSerializationDebugProperty>();
    int last = 0;
    String fieldName;
    int valuePos;
    OType type;
    while (true) {
        ORecordSerializationDebugProperty debugProperty = new ORecordSerializationDebugProperty();
        OGlobalProperty prop = null;
        try {
            final int len = OVarIntSerializer.readAsInteger(bytes);
            if (len != 0)
                debugInfo.properties.add(debugProperty);
            if (len == 0) {
                // SCAN COMPLETED
                break;
            } else if (len > 0) {
                // PARSE FIELD NAME
                fieldName = stringFromBytes(bytes.bytes, bytes.offset, len).intern();
                bytes.skip(len);
                valuePos = readInteger(bytes);
                type = readOType(bytes);
            } else {
                // LOAD GLOBAL PROPERTY BY ID
                final int id = (len * -1) - 1;
                debugProperty.globalId = id;
                prop = schema.getGlobalPropertyById(id);
                valuePos = readInteger(bytes);
                debugProperty.valuePos = valuePos;
                if (prop != null) {
                    fieldName = prop.getName();
                    if (prop.getType() != OType.ANY)
                        type = prop.getType();
                    else
                        type = readOType(bytes);
                } else {
                    continue;
                }
            }
            debugProperty.name = fieldName;
            debugProperty.type = type;
            if (valuePos != 0) {
                int headerCursor = bytes.offset;
                bytes.offset = valuePos;
                try {
                    debugProperty.value = deserializeValue(bytes, type, new ODocument());
                } catch (RuntimeException ex) {
                    debugProperty.faildToRead = true;
                    debugProperty.readingException = ex;
                    debugProperty.failPosition = bytes.offset;
                }
                if (bytes.offset > last)
                    last = bytes.offset;
                bytes.offset = headerCursor;
            } else
                debugProperty.value = null;
        } catch (RuntimeException ex) {
            debugInfo.readingFailure = true;
            debugInfo.readingException = ex;
            debugInfo.failPosition = bytes.offset;
            return debugInfo;
        }
    }
    return debugInfo;
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) OType(com.orientechnologies.orient.core.metadata.schema.OType) OGlobalProperty(com.orientechnologies.orient.core.metadata.schema.OGlobalProperty) OImmutableSchema(com.orientechnologies.orient.core.metadata.schema.OImmutableSchema) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class ORecordFactoryManager method declareRecordType.

public void declareRecordType(byte iByte, String iName, Class<? extends ORecord> iClass, final ORecordFactory iFactory) {
    if (recordTypes[iByte] != null)
        throw new OSystemException("Record type byte '" + iByte + "' already in use : " + recordTypes[iByte].getName());
    recordTypeNames[iByte] = iName;
    recordTypes[iByte] = iClass;
    recordFactories[iByte] = iFactory;
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException)

Example 3 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OChannelBinaryAsynchClient method createException.

@SuppressWarnings("unchecked")
private static RuntimeException createException(final String iClassName, final String iMessage, final Exception iPrevious) {
    RuntimeException rootException = null;
    Constructor<?> c = null;
    try {
        final Class<RuntimeException> excClass = (Class<RuntimeException>) Class.forName(iClassName);
        if (iPrevious != null) {
            try {
                c = excClass.getConstructor(String.class, Throwable.class);
            } catch (NoSuchMethodException e) {
                c = excClass.getConstructor(String.class, Exception.class);
            }
        }
        if (c == null)
            c = excClass.getConstructor(String.class);
    } catch (Exception e) {
        // UNABLE TO REPRODUCE THE SAME SERVER-SIDE EXCEPTION: THROW AN SYSTEM EXCEPTION
        rootException = OException.wrapException(new OSystemException(iMessage), iPrevious);
    }
    if (c != null)
        try {
            final Exception cause;
            if (c.getParameterTypes().length > 1)
                cause = (Exception) c.newInstance(iMessage, iPrevious);
            else
                cause = (Exception) c.newInstance(iMessage);
            rootException = OException.wrapException(new OSystemException("Data processing exception"), cause);
        } catch (InstantiationException ignored) {
        } catch (IllegalAccessException ignored) {
        } catch (InvocationTargetException ignored) {
        }
    return rootException;
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OLockException(com.orientechnologies.common.concur.lock.OLockException) OException(com.orientechnologies.common.exception.OException) SocketException(java.net.SocketException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) ONetworkProtocolException(com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException) OTimeoutException(com.orientechnologies.common.concur.OTimeoutException) OSystemException(com.orientechnologies.common.exception.OSystemException) OIOException(com.orientechnologies.common.io.OIOException) OResponseProcessingException(com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OTokenHandlerImpl method getSignedWebToken.

public byte[] getSignedWebToken(final ODatabaseDocument db, final OSecurityUser user) {
    final ByteArrayOutputStream tokenByteOS = new ByteArrayOutputStream(1024);
    final OrientJwtHeader header = new OrientJwtHeader();
    header.setAlgorithm("HS256");
    header.setKeyId("");
    final OJwtPayload payload = createPayload(db, user);
    header.setType(getPayloadType(payload));
    try {
        byte[] bytes = serializeWebHeader(header);
        tokenByteOS.write(OBase64Utils.encodeBytesToBytes(bytes, 0, bytes.length, OBase64Utils.URL_SAFE));
        tokenByteOS.write(JWT_DELIMITER);
        bytes = serializeWebPayload(payload);
        tokenByteOS.write(OBase64Utils.encodeBytesToBytes(bytes, 0, bytes.length, OBase64Utils.URL_SAFE));
        byte[] unsignedToken = tokenByteOS.toByteArray();
        tokenByteOS.write(JWT_DELIMITER);
        bytes = signToken(header, unsignedToken);
        tokenByteOS.write(OBase64Utils.encodeBytesToBytes(bytes, 0, bytes.length, OBase64Utils.URL_SAFE));
    } catch (Exception ex) {
        throw OException.wrapException(new OSystemException("Error on token parsing"), ex);
    }
    return tokenByteOS.toByteArray();
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OJwtPayload(com.orientechnologies.orient.core.metadata.security.jwt.OJwtPayload) OException(com.orientechnologies.common.exception.OException) OSystemException(com.orientechnologies.common.exception.OSystemException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 5 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OTokenHandlerImpl method verifyTokenSignature.

private boolean verifyTokenSignature(final OJwtHeader header, final byte[] base, final int baseOffset, final int baseLength, final byte[] signature) {
    final Mac mac = threadLocalMac.get();
    try {
        mac.init(getKeyProvider().getKey(header));
        mac.update(base, baseOffset, baseLength);
        final byte[] calculatedSignature = mac.doFinal();
        boolean valid = MessageDigest.isEqual(calculatedSignature, signature);
        if (!valid) {
            OLogManager.instance().warn(this, "Token signature failure: %s", OBase64Utils.encodeBytes(base));
        }
        return valid;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw OException.wrapException(new OSystemException("Token signature cannot be verified"), e);
    } finally {
        mac.reset();
    }
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) Mac(javax.crypto.Mac) OException(com.orientechnologies.common.exception.OException) OSystemException(com.orientechnologies.common.exception.OSystemException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

OSystemException (com.orientechnologies.common.exception.OSystemException)17 OException (com.orientechnologies.common.exception.OException)6 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OBinaryToken (com.orientechnologies.orient.server.binary.impl.OBinaryToken)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 OIOException (com.orientechnologies.common.io.OIOException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ONetworkProtocolException (com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException)2 OResponseProcessingException (com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 OTimeoutException (com.orientechnologies.common.concur.OTimeoutException)1 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OLockException (com.orientechnologies.common.concur.lock.OLockException)1 OConsoleDatabaseApp (com.orientechnologies.orient.console.OConsoleDatabaseApp)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)1