Search in sources :

Example 6 with OSystemException

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

the class OTokenHandlerImpl method deserializeWebHeader.

protected OrientJwtHeader deserializeWebHeader(final byte[] decodedHeader) {
    final ODocument doc = new ODocument();
    try {
        doc.fromJSON(new String(decodedHeader, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw OException.wrapException(new OSystemException("Header is not encoded in UTF-8 format"), e);
    }
    final OrientJwtHeader header = new OrientJwtHeader();
    header.setType((String) doc.field("typ"));
    header.setAlgorithm((String) doc.field("alg"));
    header.setKeyId((String) doc.field("kid"));
    return header;
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OSystemException

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

the class OTokenHandlerImpl method getSignedBinaryToken.

public byte[] getSignedBinaryToken(final ODatabaseDocumentInternal db, final OSecurityUser user, final ONetworkProtocolData data) {
    try {
        final OBinaryToken token = new OBinaryToken();
        long curTime = System.currentTimeMillis();
        final OrientJwtHeader header = new OrientJwtHeader();
        header.setAlgorithm(algorithm);
        header.setKeyId(keyProvider.getDefaultKey());
        header.setType("OrientDB");
        token.setHeader(header);
        if (db != null) {
            token.setDatabase(db.getName());
            token.setDatabaseType(db.getStorage().getUnderlying().getType());
        }
        if (data.serverUser) {
            token.setServerUser(true);
            token.setUserName(data.serverUsername);
        }
        if (user != null)
            token.setUserRid(user.getIdentity().getIdentity());
        token.setExpiry(curTime + sessionInMills);
        token.setProtocolVersion(data.protocolVersion);
        token.setSerializer(data.serializationImpl);
        token.setDriverName(data.driverName);
        token.setDriverVersion(data.driverVersion);
        return serializeSignedToken(token);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw OException.wrapException(new OSystemException("Error on token parsing"), e);
    }
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OBinaryToken(com.orientechnologies.orient.server.binary.impl.OBinaryToken) 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 8 with OSystemException

use of com.orientechnologies.common.exception.OSystemException 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 9 with OSystemException

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

the class OConsoleDatabaseApp method displayRawRecord.

@ConsoleCommand(description = "Display a record as raw bytes", onlineHelp = "Console-Command-Display-Raw-Record")
public void displayRawRecord(@ConsoleParameter(name = "rid", description = "The record id to display") final String iRecordId) throws IOException {
    checkForDatabase();
    ORecordId rid;
    if (iRecordId.indexOf(':') > -1)
        rid = new ORecordId(iRecordId);
    else {
        OIdentifiable rec = setCurrentRecord(Integer.parseInt(iRecordId));
        if (rec != null)
            rid = (ORecordId) rec.getIdentity();
        else
            return;
    }
    ORawBuffer record;
    ORecordId id = new ORecordId(rid);
    if (!(currentDatabase.getStorage() instanceof OLocalPaginatedStorage)) {
        record = currentDatabase.getStorage().readRecord(rid, null, false, false, null).getResult();
        if (record != null) {
            String content;
            if (Integer.parseInt(properties.get("maxBinaryDisplay")) < record.buffer.length)
                content = new String(Arrays.copyOf(record.buffer, Integer.parseInt(properties.get("maxBinaryDisplay"))));
            else
                content = new String(record.buffer);
            out.println("\nRaw record content. The size is " + record.buffer.length + " bytes, while settings force to print first " + content.length() + " bytes:\n\n" + content);
        }
    } else {
        final OLocalPaginatedStorage storage = (OLocalPaginatedStorage) currentDatabase.getStorage();
        final OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(id.getClusterId());
        if (cluster == null) {
            message("\n cluster with id %i does not exist", id.getClusterId());
            return;
        }
        message("\n\nLOW LEVEL CLUSTER INFO");
        final OPaginatedCluster.RECORD_STATUS status = cluster.getRecordStatus(id.getClusterPosition());
        message("\n status: %s", status);
        final OPaginatedClusterDebug debugInfo = cluster.readDebug(id.getClusterPosition());
        message("\n cluster fieldId: %d", debugInfo.fileId);
        message("\n cluster name: %s", cluster.getName());
        message("\n in cluster position: %d", debugInfo.clusterPosition);
        message("\n empty: %b", debugInfo.empty);
        message("\n contentSize: %d", debugInfo.contentSize);
        message("\n n-pages: %d", debugInfo.pages.size());
        message("\n\n +----------PAGE_ID---------------+------IN_PAGE_POSITION----------+---------IN_PAGE_SIZE-----------+----PAGE_CONTENT---->> ");
        for (OClusterPageDebug page : debugInfo.pages) {
            message("\n |%30d ", page.pageIndex);
            message(" |%30d ", page.inPagePosition);
            message(" |%30d ", page.inPageSize);
            message(" |%s", OBase64Utils.encodeBytes(page.content));
        }
        record = cluster.readRecord(id.getClusterPosition(), false);
    }
    if (record == null)
        throw new OSystemException("The record has been deleted");
    if ("ORecordSerializerBinary".equals(currentDatabase.getSerializer().toString())) {
        byte[] buff = record.getBuffer();
        ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
        ORecordSerializationDebug deserializeDebug = debugger.deserializeDebug(buff, currentDatabase);
        message("\n\nRECORD CONTENT INFO");
        message("\n class name: %s", deserializeDebug.className);
        message("\n fail on Reading: %b", deserializeDebug.readingFailure);
        message("\n fail position: %d", deserializeDebug.failPosition);
        if (deserializeDebug.readingException != null) {
            StringWriter writer = new StringWriter();
            deserializeDebug.readingException.printStackTrace(new PrintWriter(writer));
            message("\n Exception On Reading: %s", writer.getBuffer().toString());
        }
        message("\n number of properties : %d", deserializeDebug.properties.size());
        message("\n\n PROPERTIES");
        for (ORecordSerializationDebugProperty prop : deserializeDebug.properties) {
            message("\n  property name: %s", prop.name);
            message("\n  property type: %s", prop.type.name());
            message("\n  property globalId: %d", prop.globalId);
            message("\n  fail on reading: %b", prop.faildToRead);
            if (prop.faildToRead) {
                message("\n  failed on reading position: %b", prop.failPosition);
                StringWriter writer = new StringWriter();
                prop.readingException.printStackTrace(new PrintWriter(writer));
                message("\n  Exception on reading: %s", writer.getBuffer().toString());
            } else {
                if (prop.value instanceof ORidBag) {
                    message("\n  property value: ORidBug ");
                    ((ORidBag) prop.value).debugPrint(System.out);
                } else
                    message("\n  property value: %s", prop.value != null ? prop.value.toString() : "null");
            }
            message("\n");
        }
    }
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OSystemException(com.orientechnologies.common.exception.OSystemException) OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) ORecordSerializationDebugProperty(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebugProperty) ORecordSerializerBinaryDebug(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryDebug) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OClusterPageDebug(com.orientechnologies.orient.core.storage.impl.local.paginated.OClusterPageDebug) OPaginatedCluster(com.orientechnologies.orient.core.storage.impl.local.paginated.OPaginatedCluster) OPaginatedClusterDebug(com.orientechnologies.orient.core.storage.impl.local.paginated.OPaginatedClusterDebug) ORecordSerializationDebug(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 10 with OSystemException

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

the class OConsoleDatabaseApp method infoProperty.

@ConsoleCommand(description = "Display a class property", onlineHelp = "Console-Command-Info-Property")
public void infoProperty(@ConsoleParameter(name = "property-name", description = "The name of the property as <class>.<property>") final String iPropertyName) {
    checkForDatabase();
    if (iPropertyName.indexOf('.') == -1)
        throw new OSystemException("Property name is in the format <class>.<property>");
    final String[] parts = iPropertyName.split("\\.");
    final OClass cls = currentDatabase.getMetadata().getImmutableSchemaSnapshot().getClass(parts[0]);
    if (cls == null) {
        message("\n! Class '" + parts[0] + "' does not exist in the database '" + currentDatabaseName + "'");
        return;
    }
    final OProperty prop = cls.getProperty(parts[1]);
    if (prop == null) {
        message("\n! Property '" + parts[1] + "' does not exist in class '" + parts[0] + "'");
        return;
    }
    message("\nPROPERTY '" + prop.getFullName() + "'\n");
    message("\nType.................: " + prop.getType());
    message("\nMandatory............: " + prop.isMandatory());
    message("\nNot null.............: " + prop.isNotNull());
    message("\nRead only............: " + prop.isReadonly());
    message("\nDefault value........: " + prop.getDefaultValue());
    message("\nMinimum value........: " + prop.getMin());
    message("\nMaximum value........: " + prop.getMax());
    message("\nREGEXP...............: " + prop.getRegexp());
    message("\nCollate..............: " + prop.getCollate());
    message("\nLinked class.........: " + prop.getLinkedClass());
    message("\nLinked type..........: " + prop.getLinkedType());
    if (prop.getCustomKeys().size() > 0) {
        message("\n\nCUSTOM ATTRIBUTES");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (final String k : prop.getCustomKeys()) {
            try {
                final ODocument row = new ODocument();
                resultSet.add(row);
                row.field("NAME", k);
                row.field("VALUE", prop.getCustom(k));
            } catch (Exception ignored) {
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
    final Collection<OIndex<?>> indexes = prop.getAllIndexes();
    if (!indexes.isEmpty()) {
        message("\n\nINDEXES (" + indexes.size() + " altogether)");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (final OIndex<?> index : indexes) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", index.getName());
            final OIndexDefinition indexDefinition = index.getDefinition();
            if (indexDefinition != null) {
                final List<String> fields = indexDefinition.getFields();
                row.field("PROPERTIES", fields);
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OSystemException(com.orientechnologies.common.exception.OSystemException) OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

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