Search in sources :

Example 16 with CredentialGraph

use of org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticatorTest method testSetupEmptyCredGraphNoPassDefault.

@Test(expected = IllegalStateException.class)
public void testSetupEmptyCredGraphNoPassDefault() {
    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_USER, "user");
    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)

Example 17 with CredentialGraph

use of org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticatorTest method testPassEmptyCredGraphUserIndex.

@Test
public void testPassEmptyCredGraphUserIndex() {
    final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").addMockedMethod("createHMACAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final HMACAuthenticator hmacAuthenticator = createMock(HMACAuthenticator.class);
    final JanusGraphSimpleAuthenticator janusSimpleAuthenticator = createMock(JanusGraphSimpleAuthenticator.class);
    final SimpleAuthenticator simpleAuthenticator = createMock(SimpleAuthenticator.class);
    final Transaction tx = createMock(Transaction.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(janusSimpleAuthenticator);
    expect(authenticator.createHMACAuthenticator()).andReturn(hmacAuthenticator);
    hmacAuthenticator.setup(configMap);
    expectLastCall();
    expect(janusSimpleAuthenticator.createSimpleAuthenticator()).andReturn(simpleAuthenticator);
    simpleAuthenticator.setup(configMap);
    expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    tx.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Example 18 with CredentialGraph

use of org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticatorTest method testSetupDefaultUserNonEmptyCredGraph.

@Test
public void testSetupDefaultUserNonEmptyCredGraph() {
    final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").addMockedMethod("createHMACAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final JanusGraphSimpleAuthenticator janusSimpleAuthenticator = createMock(JanusGraphSimpleAuthenticator.class);
    final HMACAuthenticator hmacAuthenticator = createMock(HMACAuthenticator.class);
    final SimpleAuthenticator simpleAuthenticator = createMock(SimpleAuthenticator.class);
    final Transaction tx = createMock(Transaction.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(janusSimpleAuthenticator);
    expect(authenticator.createHMACAuthenticator()).andReturn(hmacAuthenticator);
    hmacAuthenticator.setup(configMap);
    expectLastCall();
    expect(janusSimpleAuthenticator.createSimpleAuthenticator()).andReturn(simpleAuthenticator);
    simpleAuthenticator.setup(configMap);
    expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    expect(credentialGraph.findUser("user")).andReturn(createMock(Vertex.class));
    tx.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) Test(org.junit.Test)

Example 19 with CredentialGraph

use of org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph in project janusgraph by JanusGraph.

the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyNoUserDefault.

@Test(expected = IllegalStateException.class)
public void testSetupEmptyNoUserDefault() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.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(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.countUsers()).andReturn(0l);
    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)

Example 20 with CredentialGraph

use of org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph in project janusgraph by JanusGraph.

the class JanusGraphSimpleAuthenticatorTest method testPassEmptyCredGraphUserIndex.

@Test
public void testPassEmptyCredGraphUserIndex() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
    final SimpleAuthenticator sa = createMock(SimpleAuthenticator.class);
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(sa);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    sa.setup(configMap);
    EasyMock.expectLastCall();
    graph.close();
    EasyMock.expectLastCall();
    tx.rollback();
    EasyMock.expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)20 CredentialGraph (org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph)20 JanusGraph (org.janusgraph.core.JanusGraph)20 Test (org.junit.Test)16 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)14 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)14 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 SimpleAuthenticator (org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator)5 PropertyKey (org.janusgraph.core.PropertyKey)3 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)3 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)3 PropertyKeyMaker (org.janusgraph.core.schema.PropertyKeyMaker)3 AuthenticationException (org.apache.tinkerpop.gremlin.server.auth.AuthenticationException)2