Search in sources :

Example 1 with PermissionExpressionVisitor

use of com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor in project elide by yahoo.

the class AggregationDataStore method validateModelExpressionChecks.

/**
 * Validates The security Check expression type for both Table and all its fields.
 * Table Security Check Condition - User Checks and Filter Expression Checks
 * Field Security Check Condition - User Checks
 * @param dictionary - Entity Dictionary
 * @param clz - Model Type.
 */
private void validateModelExpressionChecks(EntityDictionary dictionary, Type<?> clz) {
    PermissionExpressionVisitor visitor = new PermissionExpressionVisitor();
    ParseTree parseTree = dictionary.getPermissionsForClass(clz, ReadPermission.class);
    if (parseTree != null) {
        validateExpression(dictionary, visitor.visit(parseTree), (checkClass) -> UserCheck.class.isAssignableFrom(checkClass) || FilterExpressionCheck.class.isAssignableFrom(checkClass), "Table Can only have User Check and Filter Expression Check." + "Operation Checks Not allowed. given - %s");
    }
    dictionary.getAllExposedFields(clz).stream().map(field -> dictionary.getPermissionsForField(clz, field, ReadPermission.class)).filter(Objects::nonNull).forEach(tree -> validateExpression(dictionary, visitor.visit(tree), (checkClass) -> UserCheck.class.isAssignableFrom(checkClass), "Fields Can only have User checks. Given - %s"));
}
Also used : ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) Arrays(java.util.Arrays) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) Join(com.yahoo.elide.datastores.aggregation.annotation.Join) AccessibleObject(com.yahoo.elide.core.type.AccessibleObject) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) UserCheck(com.yahoo.elide.core.security.checks.UserCheck) PermissionExecutor(com.yahoo.elide.core.security.PermissionExecutor) Function(java.util.function.Function) ClassType(com.yahoo.elide.core.type.ClassType) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ToString(lombok.ToString) ParseTree(org.antlr.v4.runtime.tree.ParseTree) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) RequestScope(com.yahoo.elide.core.RequestScope) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Check(com.yahoo.elide.core.security.checks.Check) Cache(com.yahoo.elide.datastores.aggregation.cache.Cache) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) PermissionExpressionVisitor(com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor) NonNull(lombok.NonNull) Predicate(java.util.function.Predicate) ValueType(com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) AggregationStorePermissionExecutor(com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Objects(java.util.Objects) List(java.util.List) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Builder(lombok.Builder) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) QueryLogger(com.yahoo.elide.datastores.aggregation.core.QueryLogger) PermissionExpressionVisitor(com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor) ReadPermission(com.yahoo.elide.annotation.ReadPermission) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ReadPermission (com.yahoo.elide.annotation.ReadPermission)1 RequestScope (com.yahoo.elide.core.RequestScope)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 ArgumentType (com.yahoo.elide.core.dictionary.ArgumentType)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 PermissionExecutor (com.yahoo.elide.core.security.PermissionExecutor)1 Check (com.yahoo.elide.core.security.checks.Check)1 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)1 UserCheck (com.yahoo.elide.core.security.checks.UserCheck)1 AggregationStorePermissionExecutor (com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor)1 AccessibleObject (com.yahoo.elide.core.type.AccessibleObject)1 ClassType (com.yahoo.elide.core.type.ClassType)1 Type (com.yahoo.elide.core.type.Type)1 ColumnMeta (com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta)1 Join (com.yahoo.elide.datastores.aggregation.annotation.Join)1 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)1 Cache (com.yahoo.elide.datastores.aggregation.cache.Cache)1 QueryLogger (com.yahoo.elide.datastores.aggregation.core.QueryLogger)1 ValueType (com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType)1