use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.
the class FederatedAccessResourceAccessPredicateTest method shouldConfigureDefaultFederatedGraphAccessPredicatesWhenNoAccessPredicateConfigurationSupplied.
@Test
public void shouldConfigureDefaultFederatedGraphAccessPredicatesWhenNoAccessPredicateConfigurationSupplied() {
final FederatedAccess access = new FederatedAccess.Builder().addingUserId(testUser.getUserId()).graphAuths(ALL_USERS).build();
final AccessPredicate expectedNonPublicReadAccessPredicate = new FederatedGraphReadAccessPredicate(testUser.getUserId(), asList(ALL_USERS), false);
final AccessPredicate expectedWriteAccessPredicate = new FederatedGraphWriteAccessPredicate(testUser.getUserId());
assertEquals(expectedNonPublicReadAccessPredicate, access.getOrDefaultReadAccessPredicate());
assertEquals(expectedWriteAccessPredicate, access.getOrDefaultWriteAccessPredicate());
final FederatedAccess publicAccess = new FederatedAccess.Builder().addingUserId(testUser.getUserId()).graphAuths(ALL_USERS).makePublic().build();
final AccessPredicate expectedPublicReadAccessPredicate = new FederatedGraphReadAccessPredicate(testUser.getUserId(), asList(ALL_USERS), true);
assertEquals(expectedPublicReadAccessPredicate, publicAccess.getOrDefaultReadAccessPredicate());
assertEquals(expectedWriteAccessPredicate, publicAccess.getOrDefaultWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate 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.AccessPredicate 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());
}
use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.
the class NamedOperationDetailTest method shouldConfigureCustomReadAccessPredicateWhenSpecified.
@Test
public void shouldConfigureCustomReadAccessPredicateWhenSpecified() {
final AccessPredicate customAccessPredicate = new AccessPredicate(new CustomUserPredicate());
final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().readAccessPredicate(customAccessPredicate).build();
assertEquals(customAccessPredicate, namedOperationDetail.getReadAccessPredicate());
}
use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.
the class NamedOperationDetailTest method shouldSerialiseAndDeserialiseAccessPredicates.
@Test
public void shouldSerialiseAndDeserialiseAccessPredicates() throws SerialisationException {
NamedOperationDetail nop = new NamedOperationDetail.Builder().operationName("test").operationChain(new OperationChain.Builder().first(new GetAllElements()).build()).readAccessPredicate(new AccessPredicate("a", asList("b", "c"))).writeAccessPredicate(new AccessPredicate("x", asList("y", "z"))).build();
// When
String serialised = new String(JSONSerialiser.serialise(nop));
// Then
String expected = "{" + " \"operationName\": \"test\"," + " \"operations\": \"{\\\"class\\\":\\\"uk.gov.gchq.gaffer.operation.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.DefaultUserPredicate\"," + " \"creatingUserId\": \"a\"," + " \"auths\": [\"b\", \"c\"]" + " }" + " }," + " \"writeAccessPredicate\": {" + " \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + " \"userPredicate\": {" + " \"class\": \"uk.gov.gchq.gaffer.access.predicate.user.DefaultUserPredicate\"," + " \"creatingUserId\": \"x\"," + " \"auths\": [\"y\", \"z\"]" + " }" + " }" + "}";
JsonAssert.assertEquals(expected, serialised);
final NamedOperationDetail deserialised = JSONSerialiser.deserialise(serialised, NamedOperationDetail.class);
assertEquals(nop, deserialised);
}
Aggregations