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());
}
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());
}
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));
}
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);
}
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));
}
Aggregations