Search in sources :

Example 1 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class EntityImportExportImpl method assertToken.

protected void assertToken(Object entity, FetchPlan fetchPlan) {
    if (coreProperties.isEntitySerializationTokenRequired()) {
        SecurityState securityState = EntitySystemAccess.getSecurityState(entity);
        if (securityState.getRestoreState() == SecurityState.RestoreState.RESTORED_FROM_NULL_TOKEN) {
            MetaClass metaClass = metadata.getClass(entity.getClass());
            for (MetaProperty metaProperty : metaClass.getProperties()) {
                if (metaProperty.getRange().isClass() && metadataTools.isJpa(metaProperty) && fetchPlan.containsProperty(metaProperty.getName())) {
                    InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaProperty.getRange().asClass(), applicationContext);
                    accessManager.applyRegisteredConstraints(inMemoryContext);
                    if (inMemoryContext.readPredicate() != null) {
                        throw new EntityTokenException(format("Could not read export/import token from entity %s.", entity));
                    }
                }
            }
        }
    }
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) EntityTokenException(io.jmix.core.impl.serialization.EntityTokenException) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntitySystemAccess.getSecurityState(io.jmix.core.entity.EntitySystemAccess.getSecurityState) SecurityState(io.jmix.core.entity.SecurityState) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 2 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class SecuredListAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null) {
        return false;
    }
    Object singleSelected = target.getSingleSelected();
    if (singleSelected == null) {
        return false;
    }
    if (constraintEntityOp != null) {
        MetaClass metaClass = metadata.getClass(singleSelected.getClass());
        InMemoryCrudEntityContext context = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyRegisteredConstraints(context);
        if (constraintEntityOp == EntityOp.CREATE) {
            return context.isCreatePermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.READ) {
            return context.isReadPermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.UPDATE) {
            return context.isUpdatePermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.DELETE) {
            return context.isDeletePermitted(singleSelected);
        } else {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 3 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class StandardEditor method setupLock.

protected void setupLock() {
    Object entityId = EntityValues.getId(entityToEdit);
    if (!getEntityStates().isNew(entityToEdit) && entityId != null) {
        AccessManager accessManager = getApplicationContext().getBean(AccessManager.class);
        MetaClass metaClass = getEditedEntityContainer().getEntityMetaClass();
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, getApplicationContext());
        accessManager.applyRegisteredConstraints(inMemoryContext);
        if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || inMemoryContext.isUpdatePermitted(getEditedEntity()))) {
            readOnlyDueToLock = false;
            PessimisticLockStatus lockStatus = getLockingSupport().lock(entityId);
            if (lockStatus == PessimisticLockStatus.LOCKED) {
                justLocked = true;
                addAfterDetachListener(afterDetachEvent -> releaseLock());
            } else if (lockStatus == PessimisticLockStatus.FAILED) {
                readOnlyDueToLock = true;
                showEnableEditingBtn = false;
                setReadOnly(true);
            }
        } else {
            showEnableEditingBtn = false;
            setReadOnly(true);
        }
    }
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 4 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class ItemTrackingAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null) {
        return false;
    }
    Object singleSelected = target.getSingleSelected();
    if (singleSelected == null) {
        return false;
    }
    if (constraintEntityOp != null) {
        MetaClass metaClass = metadata.getClass(singleSelected.getClass());
        InMemoryCrudEntityContext context = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyRegisteredConstraints(context);
        if (constraintEntityOp == EntityOp.CREATE) {
            return context.isCreatePermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.READ) {
            return context.isReadPermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.UPDATE) {
            return context.isUpdatePermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.DELETE) {
            return context.isDeletePermitted(singleSelected);
        } else {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 5 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class DataStoreInMemoryCrudListener method entityLoading.

public void entityLoading(DataStoreEntityLoadingEvent event) {
    LoadContext<?> context = event.getLoadContext();
    MetaClass metaClass = extendedEntities.getEffectiveMetaClass(context.getEntityMetaClass());
    InMemoryCrudEntityContext crudContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
    accessManager.applyConstraints(crudContext, context.getAccessConstraints());
    List<Object> entities = new ArrayList<>();
    for (Object entity : event.getResultEntities()) {
        if (!crudContext.isReadPermitted(entity)) {
            log.debug("Reading entity {} is not permitted by access constraints", entity);
            event.excludeEntity(entity);
        } else {
            entities.add(entity);
        }
    }
    EntityAttributesEraser.ReferencesCollector references = entityAttributesEraser.collectErasingReferences(entities, entity -> {
        InMemoryCrudEntityContext childCrudContext = new InMemoryCrudEntityContext(metadata.getClass(entity.getClass()), applicationContext);
        accessManager.applyConstraints(childCrudContext, context.getAccessConstraints());
        boolean readPermitted = childCrudContext.isReadPermitted(entity);
        if (!readPermitted) {
            log.debug("Reading entity {} is not permitted by access constraints", entity);
        }
        return readPermitted;
    });
    event.getEventState().setValue("erasedReferences", references);
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Aggregations

InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)11 MetaClass (io.jmix.core.metamodel.model.MetaClass)10 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)3 AccessDeniedException (io.jmix.core.security.AccessDeniedException)2 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)2 EntitySystemAccess.getSecurityState (io.jmix.core.entity.EntitySystemAccess.getSecurityState)1 SecurityState (io.jmix.core.entity.SecurityState)1 EntityTokenException (io.jmix.core.impl.serialization.EntityTokenException)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1