Search in sources :

Example 11 with AccessPredicate

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());
}
Also used : FederatedGraphWriteAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate) FederatedGraphReadAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate) FederatedGraphWriteAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate) NoAccessPredicate(uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) FederatedGraphReadAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate) Test(org.junit.jupiter.api.Test)

Example 12 with AccessPredicate

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);
}
Also used : CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) FederatedGraphWriteAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate) NoAccessPredicate(uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) FederatedGraphReadAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate) Test(org.junit.jupiter.api.Test)

Example 13 with AccessPredicate

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());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 14 with AccessPredicate

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());
}
Also used : CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 15 with AccessPredicate

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);
}
Also used : GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)22 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)22 CustomUserPredicate (uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate)7 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)4 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)4 CallMethod (uk.gov.gchq.koryphe.impl.function.CallMethod)4 AdaptedPredicate (uk.gov.gchq.koryphe.predicate.AdaptedPredicate)4 NoAccessPredicate (uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate)3 FederatedGraphReadAccessPredicate (uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate)3 FederatedGraphWriteAccessPredicate (uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate)3 Context (uk.gov.gchq.gaffer.store.Context)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 User (uk.gov.gchq.gaffer.user.User)3 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)3 AccessPredicateTest (uk.gov.gchq.gaffer.access.predicate.AccessPredicateTest)2 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)2 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 CollectionContains (uk.gov.gchq.koryphe.impl.predicate.CollectionContains)2