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