Search in sources :

Example 1 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class ORestrictedAccessHook method onRecordBeforeCreate.

@Override
public RESULT onRecordBeforeCreate(final ODocument iDocument) {
    final OImmutableClass cls = ODocumentInternal.getImmutableSchemaClass(iDocument);
    if (cls != null && cls.isRestricted()) {
        String fieldNames = cls.getCustom(OSecurityShared.ONCREATE_FIELD);
        if (fieldNames == null)
            fieldNames = ORestrictedOperation.ALLOW_ALL.getFieldName();
        final String[] fields = fieldNames.split(",");
        String identityType = cls.getCustom(OSecurityShared.ONCREATE_IDENTITY_TYPE);
        if (identityType == null)
            identityType = "user";
        OIdentifiable identity = null;
        if (identityType.equals("user")) {
            final OSecurityUser user = database.getUser();
            if (user != null)
                identity = user.getIdentity();
        } else if (identityType.equals("role")) {
            final Set<? extends OSecurityRole> roles = database.getUser().getRoles();
            if (!roles.isEmpty())
                identity = roles.iterator().next().getIdentity();
        } else
            throw new OConfigurationException("Wrong custom field '" + OSecurityShared.ONCREATE_IDENTITY_TYPE + "' in class '" + cls.getName() + "' with value '" + identityType + "'. Supported ones are: 'user', 'role'");
        if (identity != null) {
            for (String f : fields) database.getMetadata().getSecurity().allowIdentity(iDocument, f, identity);
            return RESULT.RECORD_CHANGED;
        }
    }
    return RESULT.RECORD_NOT_CHANGED;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) Set(java.util.Set) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 2 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OSecurityTrackerHook method incrementSchemaVersion.

private void incrementSchemaVersion(ODocument doc) {
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(doc);
    if (immutableClass == null)
        return;
    final String className = immutableClass.getName();
    if (className.equalsIgnoreCase(OUser.CLASS_NAME) || className.equalsIgnoreCase(ORole.CLASS_NAME)) {
        final OSecurity scr = security.get();
        if (scr != null)
            scr.incrementVersion();
        if (Orient.instance().getSecurity() != null && database != null)
            Orient.instance().getSecurity().securityRecordChange(database.getURL(), doc);
    }
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass)

Example 3 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OGraphRepair method isEdgeBroken.

private boolean isEdgeBroken(final OIdentifiable vertex, final String fieldName, final Direction direction, final OIdentifiable edgeRID, final ORepairStats stats, final boolean useVertexFieldsForEdgeLabels) {
    onScannedLink(stats, edgeRID);
    boolean broken = false;
    if (edgeRID == null)
        // RID NULL
        broken = true;
    else {
        ODocument record = null;
        try {
            record = edgeRID.getIdentity().getRecord();
        } catch (ORecordNotFoundException e) {
            broken = true;
        }
        if (record == null)
            // RECORD DELETED
            broken = true;
        else {
            final OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(record);
            if (immutableClass == null || (!immutableClass.isVertexType() && !immutableClass.isEdgeType()))
                // INVALID RECORD TYPE: NULL OR NOT GRAPH TYPE
                broken = true;
            else {
                if (immutableClass.isVertexType()) {
                    // VERTEX -> LIGHTWEIGHT EDGE
                    final String inverseFieldName = OrientVertex.getInverseConnectionFieldName(fieldName, useVertexFieldsForEdgeLabels);
                    // CHECK THE VERTEX IS IN INVERSE EDGE CONTAINS
                    final Object inverseEdgeContainer = record.field(inverseFieldName);
                    if (inverseEdgeContainer == null)
                        // NULL CONTAINER
                        broken = true;
                    else {
                        if (inverseEdgeContainer instanceof OIdentifiable) {
                            if (!inverseEdgeContainer.equals(vertex))
                                // NOT THE SAME
                                broken = true;
                        } else if (inverseEdgeContainer instanceof Collection<?>) {
                            if (!((Collection) inverseEdgeContainer).contains(vertex))
                                // NOT IN COLLECTION
                                broken = true;
                        } else if (inverseEdgeContainer instanceof ORidBag) {
                            if (!((ORidBag) inverseEdgeContainer).contains(vertex))
                                // NOT IN RIDBAG
                                broken = true;
                        }
                    }
                } else {
                    // EDGE -> REGULAR EDGE, OK
                    final OIdentifiable backRID = OrientEdge.getConnection(record, direction);
                    if (backRID == null || !backRID.equals(vertex))
                        // BACK RID POINTS TO ANOTHER VERTEX
                        broken = true;
                }
            }
        }
    }
    if (broken) {
        onRemovedLink(stats, edgeRID);
        return true;
    }
    return false;
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) Collection(java.util.Collection) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OSQLFunctionLabel method getLabel.

private Object getLabel(final OrientBaseGraph graph, final OIdentifiable iCurrentRecord) {
    final ODocument rec = iCurrentRecord.getRecord();
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
    if (immutableClass.isVertexType()) {
        // VERTEX
        final OrientVertex vertex = graph.getVertex(iCurrentRecord);
        return vertex.getLabel();
    } else if (immutableClass.isEdgeType()) {
        // EDGE
        final OrientEdge edge = graph.getEdge(iCurrentRecord);
        return edge.getLabel();
    } else
        throw new OCommandExecutionException("Invalid record: is neither a vertex nor an edge. Found class: " + immutableClass);
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OSQLFunctionMove method v2v.

protected Object v2v(final OrientBaseGraph graph, final OIdentifiable iRecord, final Direction iDirection, final String[] iLabels) {
    final ODocument rec = iRecord.getRecord();
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
    if (immutableClass != null && immutableClass.isVertexType()) {
        // VERTEX
        final OrientVertex vertex = graph.getVertex(rec);
        if (vertex != null)
            return vertex.getVertices(iDirection, iLabels);
    }
    return null;
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OImmutableClass (com.orientechnologies.orient.core.metadata.schema.OImmutableClass)16 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 ORecord (com.orientechnologies.orient.core.record.ORecord)6 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 Vertex (com.tinkerpop.blueprints.Vertex)2 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)2 OException (com.orientechnologies.common.exception.OException)1 OCommandScriptException (com.orientechnologies.orient.core.command.script.OCommandScriptException)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)1 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 ORID (com.orientechnologies.orient.core.id.ORID)1