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