use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class EntityDictionary method getCheckInstance.
/**
* Returns the check mapped to a particular identifier.
*
* @param checkIdentifier the name from the expression string
* @return the {@link Check} mapped to the identifier.
*/
public Check getCheckInstance(String checkIdentifier) {
// Role checks may contain the same class for different checks.
if (roleChecks.containsKey(checkIdentifier)) {
return roleChecks.get(checkIdentifier);
}
Class<? extends Check> checkClass = getCheck(checkIdentifier);
Check check;
if (checkInstances.containsKey(checkClass)) {
check = checkInstances.get(checkClass);
} else {
check = injector.instantiate(checkClass);
injector.inject(check);
checkInstances.put(checkClass, check);
}
return check;
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class PermissionToFilterExpressionVisitorTest method filterExpressionForPermissions.
private FilterExpression filterExpressionForPermissions(String permission) {
Function<Check, Expression> checkFn = (check) -> new CheckExpression(check, null, requestScope, null, cache);
ParseTree expression = EntityPermissions.parseExpression(permission);
PermissionToFilterExpressionVisitor fev = new PermissionToFilterExpressionVisitor(dictionary, requestScope, null);
return expression.accept(new PermissionExpressionVisitor(dictionary, checkFn)).accept(NORMALIZATION_VISITOR).accept(fev);
}
use of com.yahoo.elide.core.security.checks.Check 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"));
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class AggregationStorePermissionExecutorTest method setup.
@BeforeAll
public void setup() {
Map<String, Class<? extends Check>> checks = new HashMap<>();
checks.put("user all", Role.ALL.class);
checks.put("user none", Role.NONE.class);
checks.put("filter check", FilterCheck.class);
dictionary = TestDictionary.getTestDictionary(checks);
elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class PermissionExpressionBuilderTest method setupEntityDictionary.
@BeforeEach
public void setupEntityDictionary() {
Map<String, Class<? extends Check>> checks = new HashMap<>();
checks.put("user has all access", Role.ALL.class);
checks.put("user has no access", Role.NONE.class);
dictionary = TestDictionary.getTestDictionary(checks);
ExpressionResultCache cache = new ExpressionResultCache();
builder = new PermissionExpressionBuilder(cache, dictionary);
elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
}
Aggregations