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