Search in sources :

Example 1 with CustomUserPredicate

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

the class NamedOperationDetailTest method shouldDeserialiseCustomAccessPredicate.

@Test
public void shouldDeserialiseCustomAccessPredicate() throws SerialisationException {
    // Given
    String json = "{" + "   \"operationName\": \"operationName\"," + "   \"creatorId\": \"creatorUserId\"," + "   \"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.CustomUserPredicate\"" + "       }" + "   }" + "}";
    // When
    NamedOperationDetail deserialised = JSONSerialiser.deserialise(json, NamedOperationDetail.class);
    // Then
    AccessPredicate expected = new AccessPredicate(new CustomUserPredicate());
    assertEquals(expected, deserialised.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 2 with CustomUserPredicate

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

the class NamedOperationDetailTest method shouldBeJavaSerialisable.

@Test
public void shouldBeJavaSerialisable() throws IOException, ClassNotFoundException {
    // Given
    final AccessPredicate customAccessPredicate = new AccessPredicate(new CustomUserPredicate());
    final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().readAccessPredicate(customAccessPredicate).build();
    // When
    NamedOperationDetail deserialised = (NamedOperationDetail) deserialise(serialise(namedOperationDetail));
    // Then
    assertEquals(namedOperationDetail, deserialised);
}
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 3 with CustomUserPredicate

use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate 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 4 with CustomUserPredicate

use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate 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 5 with CustomUserPredicate

use of uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate 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)

Aggregations

Test (org.junit.jupiter.api.Test)7 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)7 CustomUserPredicate (uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate)7 NoAccessPredicate (uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate)1 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)1 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)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 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 User (uk.gov.gchq.gaffer.user.User)1