use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class JanusGraphFactoryShorthandTest method testJanusGraphFactoryShorthand.
@Test
public void testJanusGraphFactoryShorthand() {
final JanusGraph g = JanusGraphFactory.open("inmemory");
g.close();
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class VertexListTest method testLists.
@Test
public void testLists() {
int num = 13;
JanusGraph g = JanusGraphFactory.open("inmemory");
StandardJanusGraphTx tx = (StandardJanusGraphTx) g.newTransaction();
VertexLongList vll = new VertexLongList(tx);
VertexArrayList val = new VertexArrayList(tx);
for (int i = 0; i < num; i++) {
JanusGraphVertex v = tx.addVertex();
vll.add(v);
val.add(v);
}
assertEquals(num, Iterables.size(vll));
assertEquals(num, Iterables.size(val));
vll.sort();
val.sort();
assertTrue(vll.isSorted());
assertTrue(val.isSorted());
for (Iterable<JanusGraphVertex> iterable : new Iterable[] { val, vll }) {
Iterator<JanusGraphVertex> iterator = iterable.iterator();
JanusGraphVertex previous = null;
for (int i = 0; i < num; i++) {
JanusGraphVertex next = iterator.next();
if (previous != null)
assertTrue(previous.longId() < next.longId());
previous = next;
}
try {
iterator.next();
fail();
} catch (NoSuchElementException ignored) {
}
}
tx.commit();
g.close();
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class JanusGraphAbstractAuthenticator method setup.
@Override
public void setup(final Map<String, Object> config) {
logger.info("Initializing authentication with the {}", this.getClass().getName());
Preconditions.checkArgument(config != null, String.format("Could not configure a %s - provide a 'config' in the 'authentication' settings", this.getClass().getName()));
Preconditions.checkState(config.containsKey(CONFIG_CREDENTIALS_DB), String.format("Credential configuration missing the %s key that points to a graph config file or graph name", CONFIG_CREDENTIALS_DB));
if (!config.containsKey(CONFIG_DEFAULT_USER) || !config.containsKey(CONFIG_DEFAULT_PASSWORD)) {
logger.warn(String.format("%s and %s should be defined to bootstrap authentication", CONFIG_DEFAULT_USER, CONFIG_DEFAULT_PASSWORD));
}
final JanusGraph graph = openGraph(config.get(CONFIG_CREDENTIALS_DB).toString());
backingGraph = graph;
credentialStore = createCredentialGraph(graph);
graph.tx().rollback();
ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
if (!mgmt.containsGraphIndex(USERNAME_INDEX_NAME)) {
final PropertyKey username = mgmt.makePropertyKey(PROPERTY_USERNAME).dataType(String.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex(USERNAME_INDEX_NAME, Vertex.class).addKey(username).unique().buildCompositeIndex();
mgmt.commit();
mgmt = (ManagementSystem) graph.openManagement();
final JanusGraphIndex index = mgmt.getGraphIndex(USERNAME_INDEX_NAME);
if (!index.getIndexStatus(username).equals(SchemaStatus.ENABLED)) {
try {
mgmt = (ManagementSystem) graph.openManagement();
mgmt.updateIndex(mgmt.getGraphIndex(USERNAME_INDEX_NAME), SchemaAction.REINDEX);
ManagementSystem.awaitGraphIndexStatus(graph, USERNAME_INDEX_NAME).status(SchemaStatus.ENABLED).call();
mgmt.commit();
} catch (InterruptedException rude) {
mgmt.rollback();
throw new RuntimeException("Timed out waiting for byUsername index to be created on credential graph", rude);
}
}
}
final String defaultUser = config.get(CONFIG_DEFAULT_USER).toString();
if (credentialStore.findUser(defaultUser) == null) {
credentialStore.createUser(defaultUser, config.get(CONFIG_DEFAULT_PASSWORD).toString());
}
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class HMACAuthenticatorTest method testAuthenticateBasicAuthValid.
@Test
public void testAuthenticateBasicAuthValid() throws AuthenticationException {
final Map<String, String> credentials = new HashMap<>();
credentials.put(PROPERTY_USERNAME, "user");
credentials.put(PROPERTY_PASSWORD, "pass");
final HMACAuthenticator authenticator = createMockBuilder(HMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(HMACAuthenticator.CONFIG_HMAC_SECRET, "secret");
configMap.put(HMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
configMap.put(HMACAuthenticator.CONFIG_DEFAULT_USER, "user");
final JanusGraph graph = createMock(JanusGraph.class);
final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
final ManagementSystem mgmt = createMock(ManagementSystem.class);
final Transaction tx = createMock(Transaction.class);
final Vertex userVertex = createMock(Vertex.class);
final String bcryptedPass = BCrypt.hashpw("pass", BCrypt.gensalt(4));
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
expect(credentialGraph.findUser(eq("user"))).andReturn(userVertex).times(2);
expect(userVertex.value(eq(PROPERTY_PASSWORD))).andReturn(bcryptedPass);
expect(graph.openManagement()).andReturn(mgmt);
expect(graph.tx()).andReturn(tx);
expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
tx.rollback();
expectLastCall();
replayAll();
authenticator.setup(configMap);
authenticator.authenticate(credentials);
verifyAll();
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class HMACAuthenticatorTest method testSetupEmptyNoUserDefault.
@Test(expected = IllegalStateException.class)
public void testSetupEmptyNoUserDefault() {
final HMACAuthenticator authenticator = createMockBuilder(HMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
final JanusGraph graph = createMock(JanusGraph.class);
final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(HMACAuthenticator.CONFIG_HMAC_SECRET, "secret");
configMap.put(HMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
authenticator.setup(configMap);
}
Aggregations