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