Search in sources :

Example 6 with JanusGraph

use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.

the class HMACAuthenticatorTest method testFailureShortenedToken.

private void testFailureShortenedToken(final Map<String, String> sharedVars) throws AuthenticationException {
    final String token = sharedVars.get("hmacToken");
    final String bcryptedPass = sharedVars.get("encryptedPass");
    final Map<String, String> credentials = new HashMap<>();
    final String encodedString = new String(Base64.getUrlDecoder().decode(token));
    final String brokenToken = encodedString.substring(0, encodedString.length() - 5);
    credentials.put(PROPERTY_TOKEN, brokenToken);
    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");
    configMap.put(HMACAuthenticator.CONFIG_HMAC_ALGO, "HmacSHA256");
    configMap.put(HMACAuthenticator.CONFIG_TOKEN_TIMEOUT, 3600000);
    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);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.findUser(eq("user"))).andReturn(userVertex).anyTimes();
    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);
    try {
        authenticator.authenticate(credentials);
        assertFalse(true);
    } catch (AuthenticationException ex) {
        assertNotNull(ex);
        verifyAll();
        resetAll();
    }
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) AuthenticationException(org.apache.tinkerpop.gremlin.server.auth.AuthenticationException) JanusGraph(org.janusgraph.core.JanusGraph)

Example 7 with JanusGraph

use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.

the class HMACAuthenticatorTest method testTokenTimeout.

private void testTokenTimeout(final Map<String, String> sharedVars) {
    final String token = sharedVars.get("hmacToken");
    final String bcryptedPass = sharedVars.get("encryptedPass");
    final Map<String, String> credentials = new HashMap<>();
    credentials.put(PROPERTY_TOKEN, new String(Base64.getUrlDecoder().decode(token)));
    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");
    configMap.put(HMACAuthenticator.CONFIG_HMAC_ALGO, "HmacSHA256");
    configMap.put(HMACAuthenticator.CONFIG_TOKEN_TIMEOUT, 1);
    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);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.findUser(eq("user"))).andReturn(userVertex).anyTimes();
    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);
    AuthenticationException ae = null;
    try {
        authenticator.authenticate(credentials);
    } catch (AuthenticationException e) {
        ae = e;
    }
    assertNotNull(ae);
    verifyAll();
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) AuthenticationException(org.apache.tinkerpop.gremlin.server.auth.AuthenticationException) JanusGraph(org.janusgraph.core.JanusGraph)

Example 8 with JanusGraph

use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.

the class HMACAuthenticatorTest method testAuthenticateBasicAuthInvalid.

@Test(expected = AuthenticationException.class)
public void testAuthenticateBasicAuthInvalid() throws AuthenticationException {
    final Map<String, String> credentials = new HashMap<>();
    credentials.put(PROPERTY_USERNAME, "user");
    credentials.put(PROPERTY_PASSWORD, "invalid");
    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.tx()).andReturn(tx);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
    tx.rollback();
    expectLastCall();
    tx.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
    authenticator.authenticate(credentials);
    verifyAll();
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Example 9 with JanusGraph

use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.

the class HMACAuthenticatorTest method testAuthenticateWithToken.

private void testAuthenticateWithToken(final Map<String, String> sharedVars) throws AuthenticationException {
    final String token = sharedVars.get("hmacToken");
    final String bcryptedPass = sharedVars.get("encryptedPass");
    final Map<String, String> credentials = new HashMap<>();
    credentials.put(PROPERTY_TOKEN, new String(Base64.getUrlDecoder().decode(token)));
    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");
    configMap.put(HMACAuthenticator.CONFIG_HMAC_ALGO, "HmacSHA256");
    configMap.put(HMACAuthenticator.CONFIG_TOKEN_TIMEOUT, 3600000);
    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);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.findUser(eq("user"))).andReturn(userVertex).anyTimes();
    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);
    assertNotNull(authenticator.authenticate(credentials));
    verifyAll();
    resetAll();
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph)

Example 10 with JanusGraph

use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticatorTest method testSetupEmptyNoUserDefault.

@Test(expected = IllegalStateException.class)
public void testSetupEmptyNoUserDefault() {
    final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.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(SaslAndHMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    authenticator.setup(configMap);
}
Also used : CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Aggregations

JanusGraph (org.janusgraph.core.JanusGraph)38 Test (org.junit.Test)23 HashMap (java.util.HashMap)20 CredentialGraph (org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph)20 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)15 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)14 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)12 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)9 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)7 SimpleAuthenticator (org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator)5 PropertyKey (org.janusgraph.core.PropertyKey)5 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)5 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)4 PropertyKeyMaker (org.janusgraph.core.schema.PropertyKeyMaker)3 LongHashSet (com.carrotsearch.hppc.LongHashSet)2 LongSet (com.carrotsearch.hppc.LongSet)2 ArrayList (java.util.ArrayList)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 AuthenticationException (org.apache.tinkerpop.gremlin.server.auth.AuthenticationException)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2