Search in sources :

Example 6 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class FederatedAddGraphHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.

@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
    store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
    final Schema expectedSchema = new Schema.Builder().build();
    assertEquals(0, store.getGraphs(testUser, null, ignore).size());
    final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
    new FederatedAddGraphHandler().doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
    assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
    assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Or(uk.gov.gchq.koryphe.impl.predicate.Or) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AdaptedPredicate(uk.gov.gchq.koryphe.predicate.AdaptedPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Example 7 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class AddNamedViewHandlerTest method shouldAddNamedViewCorrectly.

@Test
public void shouldAddNamedViewCorrectly() throws OperationException, CacheOperationFailedException {
    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(new UnrestrictedAccessPredicate(), result.getOrDefaultReadAccessPredicate());
    final AccessPredicate expectedWriteAccessPredicate = new NamedViewWriteAccessPredicate(context.getUser(), Arrays.asList(writeAccessRoles));
    assertEquals(expectedWriteAccessPredicate, result.getOrDefaultWriteAccessPredicate());
}
Also used : UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) Test(org.junit.jupiter.api.Test)

Example 8 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate 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());
}
Also used : CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) Test(org.junit.jupiter.api.Test)

Example 9 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class NamedViewDetailTest method shouldTestAccessUsingCustomAccessPredicatesWhenConfigured.

@Test
public void shouldTestAccessUsingCustomAccessPredicatesWhenConfigured() {
    // Given
    final User testUser = new User.Builder().userId("testUserId").build();
    final User differentUser = new User.Builder().userId("differentUserId").opAuth("different").build();
    final String adminAuth = "adminAuth";
    final AccessPredicate readAccessPredicate = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new IsEqual("testUserId")));
    final AccessPredicate writeAccessPredicate = new AccessPredicate(new AdaptedPredicate(new CallMethod("getOpAuths"), new CollectionContains("different")));
    // When
    final NamedViewDetail namedViewDetail = createNamedViewDetailBuilder().readAccessPredicate(readAccessPredicate).writeAccessPredicate(writeAccessPredicate).build();
    // Then
    assertTrue(namedViewDetail.hasReadAccess(testUser, adminAuth));
    assertFalse(namedViewDetail.hasReadAccess(differentUser, adminAuth));
    assertFalse(namedViewDetail.hasWriteAccess(testUser, adminAuth));
    assertTrue(namedViewDetail.hasWriteAccess(differentUser, adminAuth));
}
Also used : CollectionContains(uk.gov.gchq.koryphe.impl.predicate.CollectionContains) User(uk.gov.gchq.gaffer.user.User) AdaptedPredicate(uk.gov.gchq.koryphe.predicate.AdaptedPredicate) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Example 10 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class FederatedGraphWriteAccessPredicateTest method canBeJsonSerialisedAndDeserialised.

@Test
public void canBeJsonSerialisedAndDeserialised() throws Exception {
    final AccessPredicate predicate = createAccessPredicate(TEST_USER.getUserId());
    final byte[] bytes = JSONSerialiser.serialise(predicate);
    assertEquals("{" + "\"class\":\"uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate\"," + "\"userPredicate\":{\"class\":\"uk.gov.gchq.gaffer.federatedstore.access.predicate.user.FederatedGraphWriteUserPredicate\",\"creatingUserId\":\"TestUser\"}" + "}", new String(bytes, CommonConstants.UTF_8));
    assertEquals(predicate, JSONSerialiser.deserialise(bytes, FederatedGraphWriteAccessPredicate.class));
}
Also used : AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test) AccessPredicateTest(uk.gov.gchq.gaffer.access.predicate.AccessPredicateTest)

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