Search in sources :

Example 1 with AdaptedPredicate

use of uk.gov.gchq.koryphe.predicate.AdaptedPredicate 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 2 with AdaptedPredicate

use of uk.gov.gchq.koryphe.predicate.AdaptedPredicate 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 3 with AdaptedPredicate

use of uk.gov.gchq.koryphe.predicate.AdaptedPredicate in project Gaffer by gchq.

the class FederatedAccessAuthTest method shouldSerialiseAndDeserialiseAccessPredicatesToJson.

@Test
public void shouldSerialiseAndDeserialiseAccessPredicatesToJson() throws SerialisationException {
    // Given
    final FederatedAccess federatedAccess = new FederatedAccess.Builder().addingUserId(AUTH_USER_ID).isPublic(false).readAccessPredicate(new AccessPredicate(new AdaptedPredicate(new CallMethod("getDataAuths"), new CollectionContains(ALL_USERS)))).writeAccessPredicate(new AccessPredicate(new AdaptedPredicate(new CallMethod("getDataAuths"), new CollectionContains(AUTH_1)))).build();
    // When
    final String serialised = new String(JSONSerialiser.serialise(federatedAccess));
    // Then
    final String expected = "{" + "   \"addingUserId\": \"authUser\"," + "   \"disabledByDefault\": false," + "   \"public\": false," + "   \"readAccessPredicate\": {" + "       \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + "       \"userPredicate\": {" + "           \"class\": \"uk.gov.gchq.koryphe.predicate.AdaptedPredicate\"," + "           \"inputAdapter\": {" + "               \"class\": \"uk.gov.gchq.koryphe.impl.function.CallMethod\"," + "               \"method\": \"getDataAuths\"" + "           }," + "           \"predicate\": {" + "               \"class\": \"uk.gov.gchq.koryphe.impl.predicate.CollectionContains\"," + "               \"value\": \"allUsers\"" + "           }" + "       }" + "   }," + "   \"writeAccessPredicate\": {" + "       \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + "       \"userPredicate\": {" + "           \"class\": \"uk.gov.gchq.koryphe.predicate.AdaptedPredicate\"," + "           \"inputAdapter\": {" + "               \"class\": \"uk.gov.gchq.koryphe.impl.function.CallMethod\"," + "               \"method\": \"getDataAuths\"" + "           }," + "           \"predicate\": {" + "               \"class\": \"uk.gov.gchq.koryphe.impl.predicate.CollectionContains\"," + "               \"value\": \"auth1\"" + "           }" + "       }" + "   }" + "}";
    JsonAssert.assertEquals(expected, serialised);
    final FederatedAccess deserialised = JSONSerialiser.deserialise(serialised, FederatedAccess.class);
    assertEquals(federatedAccess, deserialised);
}
Also used : CollectionContains(uk.gov.gchq.koryphe.impl.predicate.CollectionContains) AdaptedPredicate(uk.gov.gchq.koryphe.predicate.AdaptedPredicate) FederatedGraphWriteAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) FederatedGraphReadAccessPredicate(uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) Test(org.junit.jupiter.api.Test)

Example 4 with AdaptedPredicate

use of uk.gov.gchq.koryphe.predicate.AdaptedPredicate in project Gaffer by gchq.

the class FederatedAddGraphWithHooksHandlerTest 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 FederatedAddGraphWithHooksHandler().doOperation(new AddGraphWithHooks.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)

Aggregations

Test (org.junit.jupiter.api.Test)4 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)4 CallMethod (uk.gov.gchq.koryphe.impl.function.CallMethod)4 AdaptedPredicate (uk.gov.gchq.koryphe.predicate.AdaptedPredicate)4 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)3 Context (uk.gov.gchq.gaffer.store.Context)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)2 CollectionContains (uk.gov.gchq.koryphe.impl.predicate.CollectionContains)2 Or (uk.gov.gchq.koryphe.impl.predicate.Or)2 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)1 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)1 FederatedGraphReadAccessPredicate (uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate)1 FederatedGraphWriteAccessPredicate (uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate)1 User (uk.gov.gchq.gaffer.user.User)1