use of org.apache.tinkerpop.gremlin.structure.Transaction in project janusgraph by JanusGraph.
the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.
@Test
public void testSetupEmptyCredGraphNoUserIndex() {
final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
configMap.put(JanusGraphSimpleAuthenticator.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 PropertyKey pk = createMock(PropertyKey.class);
final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
final JanusGraphIndex index = createMock(JanusGraphIndex.class);
final PropertyKey[] pks = { pk };
final SimpleAuthenticator sa = createMock(SimpleAuthenticator.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(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();
expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
expect(pkm.dataType(eq(String.class))).andReturn(pkm);
expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
expect(pkm.make()).andReturn(pk);
expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
expect(indexBuilder.unique()).andReturn(indexBuilder);
expect(indexBuilder.buildCompositeIndex()).andReturn(index);
expect(index.getFieldKeys()).andReturn(pks);
expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
expect(graph.tx()).andReturn(tx);
expect(graph.openManagement()).andReturn(mgmt);
tx.rollback();
EasyMock.expectLastCall().atLeastOnce();
mgmt.commit();
EasyMock.expectLastCall();
mgmt.rollback();
EasyMock.expectLastCall();
replayAll();
authenticator.setup(configMap);
}
use of org.apache.tinkerpop.gremlin.structure.Transaction 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.apache.tinkerpop.gremlin.structure.Transaction in project janusgraph by JanusGraph.
the class HMACAuthenticatorTest method testSetupDefaultUserNonEmptyCredGraph.
@Test
public void testSetupDefaultUserNonEmptyCredGraph() {
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);
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
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);
}
use of org.apache.tinkerpop.gremlin.structure.Transaction in project janusgraph by JanusGraph.
the class HMACAuthenticatorTest method testPassEmptyCredGraphUserIndex.
@Test
public void testPassEmptyCredGraphUserIndex() {
final HMACAuthenticator authenticator = createMockBuilder(HMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
final Map<String, Object> configMap = new HashMap<>();
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);
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
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);
}
use of org.apache.tinkerpop.gremlin.structure.Transaction in project janusgraph by JanusGraph.
the class HMACAuthenticatorTest method testAuthenticateGenerateToken.
private Map<String, String> testAuthenticateGenerateToken() throws AuthenticationException {
final Map<String, String> credentials = new HashMap<>();
credentials.put(PROPERTY_USERNAME, "user");
credentials.put(PROPERTY_PASSWORD, "pass");
credentials.put(PROPERTY_GENERATE_TOKEN, "true");
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");
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).anyTimes();
expect(userVertex.value(eq(PROPERTY_PASSWORD))).andReturn(bcryptedPass).times(2);
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));
final String hmacToken = credentials.get(PROPERTY_TOKEN);
assertNotNull(hmacToken);
verifyAll();
resetAll();
final Map<String, String> sharedVars = new HashMap<>();
sharedVars.put("hmacToken", hmacToken);
sharedVars.put("encryptedPass", bcryptedPass);
return sharedVars;
}
Aggregations