Search in sources :

Example 1 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class OperationChainLimiter method preExecute.

/**
     * Checks the {@link OperationChain}
     * is allowed to be executed by the user.
     * This is done by checking the user's auths against the auth scores getting the users maximum score limit value.
     * Then checking the operation score of all operations in the chain and comparing the total score value of the chain against a users maximum score limit.
     * If an operation cannot be executed then an {@link IllegalAccessError} is thrown.
     *
     * @param user    the user to authorise.
     * @param opChain the operation chain.
     */
@Override
public void preExecute(final OperationChain<?> opChain, final User user) {
    if (null != opChain) {
        Integer chainScore = 0;
        Integer maxAuthScore = getMaxUserAuthScore(user.getOpAuths());
        for (final Operation operation : opChain.getOperations()) {
            chainScore += authorise(operation);
            if (chainScore > maxAuthScore) {
                throw new UnauthorisedException("The maximum score limit for this user is " + maxAuthScore + ".\n" + "The requested operation chain exceeded this score limit.");
            }
        }
    }
}
Also used : UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Operation(uk.gov.gchq.gaffer.operation.Operation)

Example 2 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class AddNamedOperationHandler method validate.

private void validate(final User user, final List<String> parentOperations, final OperationChain<?> operationChain, final INamedOperationCache cache) throws CacheOperationFailedException, OperationException {
    for (final Operation op : operationChain.getOperations()) {
        if (op instanceof NamedOperation) {
            if (parentOperations.contains(((NamedOperation) op).getOperationName())) {
                throw new OperationException("The Operation Chain must not be recursive");
            }
            ExtendedNamedOperation operation = cache.getNamedOperation(((NamedOperation) op).getOperationName(), user);
            if (operation == null) {
                throw new OperationException("The Operation " + ((NamedOperation) op).getOperationName() + " references an operation which doesn't exist. Unable to create operation");
            }
            parentOperations.add(((NamedOperation) op).getOperationName());
            validate(user, parentOperations, operation.getOperationChain(), cache);
            parentOperations.remove(((NamedOperation) op).getOperationName());
        }
    }
}
Also used : AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 3 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class GraphConfigurationServiceTest method setup.

@Before
public void setup() {
    final Store store = mock(Store.class);
    final Schema schema = mock(Schema.class);
    final Set<StoreTrait> traits = new HashSet<>(Arrays.asList(STORE_AGGREGATION, PRE_AGGREGATION_FILTERING, POST_TRANSFORMATION_FILTERING, POST_AGGREGATION_FILTERING, TRANSFORMATION, STORE_VALIDATION));
    given(store.getSchema()).willReturn(schema);
    final Graph graph = new Graph.Builder().store(store).build();
    final Set<Class<? extends Operation>> operations = new HashSet<>();
    operations.add(AddElements.class);
    given(graphFactory.getGraph()).willReturn(graph);
    given(graph.getSupportedOperations()).willReturn(operations);
    given(graph.isSupported(AddElements.class)).willReturn(true);
    given(userFactory.createUser()).willReturn(new User());
    given(graph.getStoreTraits()).willReturn(traits);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 4 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class NamedOperation method getOperations.

@Override
@JsonIgnore
public List<Operation> getOperations() {
    final List<Operation> operations = new ArrayList<>();
    if (null != parameters) {
        for (final Map.Entry<String, Object> parameterDetailPair : parameters.entrySet()) {
            Object paramValue = parameterDetailPair.getValue();
            if (paramValue instanceof Operation) {
                Operation operation = (Operation) paramValue;
                operations.add(operation);
            }
        }
    }
    return operations;
}
Also used : ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 5 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class GetWalks method validate.

@Override
public ValidationResult validate() {
    final ValidationResult result = InputOutput.super.validate();
    final int getEdgeOperations = getNumberOfGetEdgeOperations();
    if (getEdgeOperations < 1) {
        result.addError("No hops were provided. " + HOP_DEFINITION);
    } else {
        int i = 0;
        for (final OperationChain<Iterable<Element>> operation : operations) {
            if (operation.getOperations().isEmpty()) {
                result.addError("Operation chain " + i + " contains no operations");
            } else {
                final Operation firstOp = operation.getOperations().get(0);
                if (firstOp instanceof Input) {
                    if (null != ((Input) firstOp).getInput()) {
                        result.addError("The input for operations must be null.");
                    }
                } else {
                    result.addError("The first operation in operation chain " + i + ": " + firstOp.getClass().getName() + " is not be able to accept the input seeds. It must implement " + Input.class.getName());
                }
            }
            if (getNumberOfGetEdgeOperationsWithoutRepeats(operation) < 1 && i < (operations.size() - 1)) {
                // An operation does not contain a hop
                result.addError("All operations must contain a single hop. Operation " + i + " does not contain a hop. The only exception is the last operation, which is allowed to just fetch Entities. " + HOP_DEFINITION);
            } else if (getNumberOfGetEdgeOperationsWithoutRepeats(operation) > 1) {
                // An operation does not contain a hop
                result.addError("All operations must contain a single hop. Operation " + i + " contains multiple hops.");
            }
            i++;
        }
    }
    return result;
}
Also used : Input(uk.gov.gchq.gaffer.operation.io.Input) MultiEntityIdInput(uk.gov.gchq.gaffer.operation.io.MultiEntityIdInput) Operation(uk.gov.gchq.gaffer.operation.Operation) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13