use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.
the class FederatedStoreTest method shouldAddGraphIdWithAuths.
@Test
public void shouldAddGraphIdWithAuths() throws Exception {
// Given
final Graph fedGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId(FEDERATED_STORE_ID).library(library).build()).addStoreProperties(federatedProperties).build();
addGraphWithIds(ACC_ID_2, ID_PROPS_ACC_2, ID_SCHEMA_ENTITY);
library.add(ACC_ID_2, getSchemaFromPath(PATH_BASIC_ENTITY_SCHEMA_JSON), PROPERTIES_ALT);
// When
int before = 0;
for (String ignore : fedGraph.execute(new GetAllGraphIds(), blankUser)) {
before++;
}
fedGraph.execute(new AddGraph.Builder().graphAuths("auth").graphId(ACC_ID_2).build(), blankUser);
int after = 0;
for (String ignore : fedGraph.execute(new GetAllGraphIds(), blankUser)) {
after++;
}
fedGraph.execute(new AddElements.Builder().input(new Entity.Builder().group("BasicEntity").vertex("v1").build()).build(), blankUser);
final CloseableIterable<? extends Element> elements = fedGraph.execute(new GetAllElements(), new User.Builder().userId(TEST_USER_ID + "Other").opAuth("auth").build());
final CloseableIterable<? extends Element> elements2 = fedGraph.execute(new GetAllElements(), new User.Builder().userId(TEST_USER_ID + "Other").opAuths("x").build());
assertEquals(0, Iterables.size(elements2));
// Then
assertEquals(0, before);
assertEquals(1, after);
assertNotNull(elements);
assertTrue(elements.iterator().hasNext());
}
use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.
the class FederatedAdminIT method shouldNotChangeGraphUserFromSomeoneElseToReplacementUserAsAdminWhenNotRequestingAdminAccess.
@Test
public void shouldNotChangeGraphUserFromSomeoneElseToReplacementUserAsAdminWhenNotRequestingAdminAccess() throws Exception {
// given
final String graphA = "graphA";
final User replacementUser = new User("replacement");
graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("Auths1").build(), user);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), replacementUser))).doesNotContain(graphA);
// when
final Boolean changed = graph.execute(new ChangeGraphAccess.Builder().graphId(graphA).ownerUserId(replacementUser.getUserId()).build(), ADMIN_USER);
// then
assertThat(changed).isFalse();
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), replacementUser))).doesNotContain(graphA);
}
use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.
the class FederatedAdminIT method shouldNotChangeGraphIdForNonOwnedGraphAsNonAdminWhenRequestingAdminAccess.
@Test
public void shouldNotChangeGraphIdForNonOwnedGraphAsNonAdminWhenRequestingAdminAccess() throws Exception {
// given
final String graphA = "graphA";
final String graphB = "graphB";
final User otherUser = new User("other");
graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("Auths1").build(), user);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), otherUser))).doesNotContain(graphA);
// when
final Boolean changed = graph.execute(new ChangeGraphId.Builder().graphId(graphA).newGraphId(graphB).option(FederatedStoreConstants.KEY_FEDERATION_ADMIN, "true").build(), otherUser);
// then
assertThat(changed).isFalse();
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA).doesNotContain(graphB);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), otherUser))).doesNotContain(graphA, graphB);
}
use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.
the class FederatedAdminIT method shouldNotChangeGraphUserFromSomeoneElseToReplacementUserAsNonAdminWhenRequestingAdminAccess.
@Test
public void shouldNotChangeGraphUserFromSomeoneElseToReplacementUserAsNonAdminWhenRequestingAdminAccess() throws Exception {
// given
final String graphA = "graphA";
final User replacementUser = new User("replacement");
graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("Auths1").build(), user);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), replacementUser))).doesNotContain(graphA);
// when
final Boolean changed = graph.execute(new ChangeGraphAccess.Builder().graphId(graphA).ownerUserId(replacementUser.getUserId()).option(FederatedStoreConstants.KEY_FEDERATION_ADMIN, "true").build(), replacementUser);
// then
assertThat(changed).isFalse();
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), replacementUser))).doesNotContain(graphA);
}
use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.
the class FederatedAdminIT method shouldChangeGraphIdForNonOwnedGraphAsAdminWhenRequestingAdminAccess.
@Test
public void shouldChangeGraphIdForNonOwnedGraphAsAdminWhenRequestingAdminAccess() throws Exception {
// given
final String graphA = "graphA";
final String graphB = "graphB";
graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("Auths1").build(), user);
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
// when
final Boolean changed = graph.execute(new ChangeGraphId.Builder().graphId(graphA).newGraphId(graphB).option(FederatedStoreConstants.KEY_FEDERATION_ADMIN, "true").build(), ADMIN_USER);
// then
assertThat(changed).isTrue();
assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).doesNotContain(graphA).contains(graphB);
}
Aggregations