Search in sources :

Example 1 with EntitySystemAccess.getSecurityState

use of io.jmix.core.entity.EntitySystemAccess.getSecurityState 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)

Aggregations

InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)1 EntitySystemAccess.getSecurityState (io.jmix.core.entity.EntitySystemAccess.getSecurityState)1 SecurityState (io.jmix.core.entity.SecurityState)1 EntityTokenException (io.jmix.core.impl.serialization.EntityTokenException)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1