Search in sources :

Example 16 with AccessPredicate

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

the class NamedOperationDetailTest method shouldConfigureCustomWriteAccessPredicateWhenSpecified.

@Test
public void shouldConfigureCustomWriteAccessPredicateWhenSpecified() {
    final AccessPredicate customAccessPredicate = new AccessPredicate(new CustomUserPredicate());
    final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().writeAccessPredicate(customAccessPredicate).build();
    assertEquals(customAccessPredicate, namedOperationDetail.getWriteAccessPredicate());
}
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 17 with AccessPredicate

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

the class NamedViewDetailTest method shouldCreatePredicatesIfNotSpecifiedInJson.

@Test
public void shouldCreatePredicatesIfNotSpecifiedInJson() throws IOException {
    // Given
    final String json = String.format("{%n" + "  \"name\" : \"view1\",%n" + "  \"description\" : \"description\",%n" + "  \"creatorId\" : \"creator\",%n" + "  \"writeAccessRoles\" : [ \"writeAuth1\", \"writeAuth2\" ],%n" + "  \"parameters\" : {%n" + "    \"entityGroup\" : {%n" + "      \"description\" : \"some description\",%n" + "      \"defaultValue\" : \"red\",%n" + "      \"valueClass\" : \"java.lang.String\",%n" + "      \"required\" : false%n" + "    }%n" + "  },%n" + "  \"view\" : \"{\\\"entities\\\": {\\\"${entityGroup}\\\":{}}}\",%n" + "  \"readAccessPredicate\" : {%n" + "       \"class\" : \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\",%n" + "       \"userPredicate\" : {%n" + "           \"class\" : \"uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate\"%n" + "       }%n" + "   }%n" + "}%n");
    // When
    NamedViewDetail deserialised = JsonSerialiser.deserialise(json, NamedViewDetail.class);
    // Then
    AccessPredicate expected = new NamedViewWriteAccessPredicate("creator", asList("writeAuth1", "writeAuth2"));
    assertEquals(expected, deserialised.getOrDefaultWriteAccessPredicate());
}
Also used : 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) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) Test(org.junit.jupiter.api.Test)

Example 18 with AccessPredicate

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

the class NamedViewWriteAccessPredicateTest method canBeJsonSerialisedAndDeserialised.

@Test
@Override
public void canBeJsonSerialisedAndDeserialised() throws Exception {
    final AccessPredicate predicate = createAccessPredicate(TEST_USER, asList("auth1", "auth2"));
    final byte[] bytes = JSONSerialiser.serialise(predicate);
    assertEquals("{" + "\"class\":\"uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate\"," + "\"userPredicate\":{" + "\"class\":\"uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.user.NamedViewWriteUserPredicate\"," + "\"creatingUserId\":\"TestUser\"," + "\"auths\":[\"auth1\",\"auth2\"]" + "}" + "}", new String(bytes, CommonConstants.UTF_8));
    assertEquals(predicate, JSONSerialiser.deserialise(bytes, NamedViewWriteAccessPredicate.class));
}
Also used : AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test) DefaultAccessPredicateTest(uk.gov.gchq.gaffer.access.predicate.DefaultAccessPredicateTest)

Example 19 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate 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 20 with AccessPredicate

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

the class FederatedGraphReadAccessPredicateTest method canBeJsonSerialisedAndDeserialised.

@Test
public void canBeJsonSerialisedAndDeserialised() throws Exception {
    final AccessPredicate predicate = createAccessPredicate(TEST_USER.getUserId(), asList("auth1", "auth2"), NON_PUBLIC);
    final byte[] bytes = JSONSerialiser.serialise(predicate);
    assertEquals("{" + "\"class\":\"uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate\"," + "\"userPredicate\":{\"class\":\"uk.gov.gchq.gaffer.federatedstore.access.predicate.user.FederatedGraphReadUserPredicate\",\"creatingUserId\":\"TestUser\",\"auths\":[\"auth1\",\"auth2\"],\"public\":false}" + "}", new String(bytes, CommonConstants.UTF_8));
    assertEquals(predicate, JSONSerialiser.deserialise(bytes, FederatedGraphReadAccessPredicate.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