Search in sources :

Example 1 with FederatedAccess

use of uk.gov.gchq.gaffer.federatedstore.FederatedAccess in project Gaffer by gchq.

the class FederatedAdminIT method shouldChangeGraphAccessIdInCache.

@Test
public void shouldChangeGraphAccessIdInCache() throws Exception {
    // given
    FederatedStoreCache federatedStoreCache = new FederatedStoreCache();
    final String graphA = "graphA";
    graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).build(), user);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
    // when
    FederatedAccess before = federatedStoreCache.getAccessFromCache(graphA);
    final Boolean changed = graph.execute(new ChangeGraphAccess.Builder().graphId(graphA).ownerUserId(ADMIN_USER.getUserId()).build(), user);
    FederatedAccess after = federatedStoreCache.getAccessFromCache(graphA);
    // then
    assertThat(changed).isTrue();
    assertThat(after).isNotEqualTo(before);
    assertThat(before.getAddingUserId()).isEqualTo(user.getUserId());
    assertThat(after.getAddingUserId()).isEqualTo(ADMIN_USER.getUserId());
}
Also used : AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) FederatedStoreCache(uk.gov.gchq.gaffer.federatedstore.FederatedStoreCache) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) FederatedAccess(uk.gov.gchq.gaffer.federatedstore.FederatedAccess) Test(org.junit.jupiter.api.Test)

Example 2 with FederatedAccess

use of uk.gov.gchq.gaffer.federatedstore.FederatedAccess in project Gaffer by gchq.

the class FederatedAdminIT method shouldGetAllGraphInfoForAdmin.

@Test
public void shouldGetAllGraphInfoForAdmin() throws Exception {
    // given
    final String graphA = "graphA";
    graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("authsValueA").build(), user);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
    final FederatedAccess expectedFedAccess = new FederatedAccess.Builder().addingUserId(user.getUserId()).graphAuths("authsValueA").makePrivate().build();
    // when
    final Map<String, Object> allGraphsAndAuths = graph.execute(new GetAllGraphInfo.Builder().option(FederatedStoreConstants.KEY_FEDERATION_ADMIN, "true").build(), ADMIN_USER);
    // then
    assertThat(allGraphsAndAuths).hasSize(1);
    assertThat(allGraphsAndAuths.keySet().toArray(new String[] {})[0]).isEqualTo(graphA);
    assertThat(allGraphsAndAuths.values().toArray(new Object[] {})[0]).isEqualTo(expectedFedAccess);
}
Also used : GetAllGraphInfo(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphInfo) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) FederatedAccess(uk.gov.gchq.gaffer.federatedstore.FederatedAccess) Test(org.junit.jupiter.api.Test)

Example 3 with FederatedAccess

use of uk.gov.gchq.gaffer.federatedstore.FederatedAccess in project Gaffer by gchq.

the class FederatedAdminIT method shouldGetGraphInfoForSelectedGraphsOnly.

@Test
public void shouldGetGraphInfoForSelectedGraphsOnly() throws Exception {
    // given
    final String graphA = "graphA";
    graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("authsValueA").build(), user);
    final String graphB = "graphB";
    graph.execute(new AddGraph.Builder().graphId(graphB).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("authsValueB").build(), user);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA, graphB);
    final FederatedAccess expectedFedAccess = new FederatedAccess.Builder().addingUserId(user.getUserId()).graphAuths("authsValueB").makePrivate().build();
    // when
    final Map<String, Object> allGraphsAndAuths = graph.execute(new GetAllGraphInfo.Builder().option(KEY_OPERATION_OPTIONS_GRAPH_IDS, graphB).build(), user);
    // then
    assertThat(allGraphsAndAuths).hasSize(1).hasSize(1);
    assertThat(allGraphsAndAuths.keySet().toArray(new String[] {})[0]).isEqualTo(graphB);
    assertThat(allGraphsAndAuths.values().toArray(new Object[] {})[0]).isEqualTo(expectedFedAccess);
}
Also used : GetAllGraphInfo(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphInfo) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) FederatedAccess(uk.gov.gchq.gaffer.federatedstore.FederatedAccess) Test(org.junit.jupiter.api.Test)

Example 4 with FederatedAccess

use of uk.gov.gchq.gaffer.federatedstore.FederatedAccess in project Gaffer by gchq.

the class FederatedChangeGraphAccessHandler method doOperation.

@Override
public Boolean doOperation(final ChangeGraphAccess operation, final Context context, final Store store) throws OperationException {
    try {
        final boolean userRequestingAdminUsage = FederatedStoreUtil.isUserRequestingAdminUsage(operation);
        final FederatedAccess federatedAccess = new FederatedAccess(operation.getGraphAuths(), operation.getOwnerUserId(), operation.getIsPublic(), operation.isDisabledByDefault());
        final User user = context.getUser();
        return ((FederatedStore) store).changeGraphAccess(user, operation.getGraphId(), federatedAccess, userRequestingAdminUsage);
    } catch (final Exception e) {
        throw new OperationException("Error changing graph access", e);
    }
}
Also used : User(uk.gov.gchq.gaffer.user.User) FederatedAccess(uk.gov.gchq.gaffer.federatedstore.FederatedAccess) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Aggregations

FederatedAccess (uk.gov.gchq.gaffer.federatedstore.FederatedAccess)4 Test (org.junit.jupiter.api.Test)3 GetAllGraphIds (uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 GetAllGraphInfo (uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphInfo)2 FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)1 FederatedStoreCache (uk.gov.gchq.gaffer.federatedstore.FederatedStoreCache)1 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 User (uk.gov.gchq.gaffer.user.User)1