use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate in project Gaffer by gchq.
the class NamedOperationDetailTest method shouldDeserialiseCustomAccessPredicate.
@Test
public void shouldDeserialiseCustomAccessPredicate() throws SerialisationException {
// Given
String json = "{" + " \"operationName\": \"operationName\"," + " \"creatorId\": \"creatorUserId\"," + " \"operationChain\": {\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\"}]}," + " \"readAccessPredicate\": {" + " \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + " \"userPredicate\": {" + " \"class\": \"uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate\"" + " }" + " }" + "}";
// When
NamedOperationDetail deserialised = JSONSerialiser.deserialise(json, NamedOperationDetail.class);
// Then
AccessPredicate expected = new AccessPredicate(new CustomUserPredicate());
assertEquals(expected, deserialised.getReadAccessPredicate());
}
use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate in project Gaffer by gchq.
the class NamedOperationDetailTest method shouldBeJavaSerialisable.
@Test
public void shouldBeJavaSerialisable() throws IOException, ClassNotFoundException {
// Given
final AccessPredicate customAccessPredicate = new AccessPredicate(new CustomUserPredicate());
final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().readAccessPredicate(customAccessPredicate).build();
// When
NamedOperationDetail deserialised = (NamedOperationDetail) deserialise(serialise(namedOperationDetail));
// Then
assertEquals(namedOperationDetail, deserialised);
}
use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate in project Gaffer by gchq.
the class AddNamedViewHandlerTest method shouldAddNamedViewContainingCustomAccessPredicatesCorrectly.
@Test
public void shouldAddNamedViewContainingCustomAccessPredicatesCorrectly() throws OperationException, CacheOperationFailedException {
final AccessPredicate readAccessPredicate = new AccessPredicate(new CustomUserPredicate());
final AccessPredicate writeAccessPredicate = new AccessPredicate(new CustomUserPredicate());
addNamedView.setReadAccessPredicate(readAccessPredicate);
addNamedView.setWriteAccessRoles(null);
addNamedView.setWriteAccessPredicate(writeAccessPredicate);
handler.doOperation(addNamedView, context, store);
final NamedViewDetail result = namedViewCache.getNamedView(testNamedViewName);
assertTrue(cacheContains(testNamedViewName));
assertEquals(addNamedView.getName(), result.getName());
assertEquals(new String(addNamedView.getView().toCompactJson()), result.getView());
assertEquals(context.getUser().getUserId(), result.getCreatorId());
assertEquals(readAccessPredicate, result.getOrDefaultReadAccessPredicate());
assertEquals(writeAccessPredicate, result.getOrDefaultWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate in project Gaffer by gchq.
the class FederatedAccessResourceAccessPredicateTest method shouldBeSerialisableWhenUsingCustomPredicate.
@Test
public void shouldBeSerialisableWhenUsingCustomPredicate() throws IOException, ClassNotFoundException {
// Given
FederatedAccess access = new FederatedAccess.Builder().addingUserId(testUser.getUserId()).graphAuths(ALL_USERS).writeAccessPredicate(new AccessPredicate(new CustomUserPredicate())).build();
// When
FederatedAccess deserialised = (FederatedAccess) deserialise(serialise(access));
// Then
assertEquals(access, deserialised);
}
use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldAddCustomAccessPredicateFieldsToNamedOperationDetailCorrectly.
@Test
public void shouldAddCustomAccessPredicateFieldsToNamedOperationDetailCorrectly() throws OperationException, CacheOperationFailedException {
final AccessPredicate readAccessPredicate = new AccessPredicate(new CustomUserPredicate());
final AccessPredicate writeAccessPredicate = new AccessPredicate(new CustomUserPredicate());
OperationChain opChain = new OperationChain.Builder().first(new AddElements()).build();
addNamedOperation.setOperationChain(opChain);
addNamedOperation.setScore(2);
addNamedOperation.setOperationName("testOp");
addNamedOperation.setLabels(asList("test label"));
addNamedOperation.setReadAccessRoles(null);
addNamedOperation.setReadAccessPredicate(readAccessPredicate);
addNamedOperation.setWriteAccessRoles(null);
addNamedOperation.setWriteAccessPredicate(writeAccessPredicate);
handler.doOperation(addNamedOperation, context, store);
final NamedOperationDetail result = mockCache.getNamedOperation("testOp", new User(), EMPTY_ADMIN_AUTH);
assert cacheContains("testOp");
assertTrue(result.getScore() == 2);
assertEquals(asList("test label"), result.getLabels());
assertEquals(readAccessPredicate, result.getReadAccessPredicate());
assertEquals(writeAccessPredicate, result.getWriteAccessPredicate());
}
Aggregations