use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testGetTarget.
@Test
public void testGetTarget() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id = authManager.createTarget(makeTarget("target-test", "url1"));
HugeTarget target = authManager.getTarget(id);
Assert.assertEquals("target-test", target.name());
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getTarget(IdGenerator.of("fake"));
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getTarget(null);
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
authManager.getTarget(user);
});
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testDelProject.
@Test
public void testDelProject() {
HugeProject project = makeProject("test_project", null);
AuthManager authManager = graph().authManager();
Id projectId = authManager.createProject(project);
Assert.assertNotNull(projectId);
HugeProject deletedProject = authManager.deleteProject(projectId);
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getProject(projectId);
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getGroup(IdGenerator.of(deletedProject.adminGroupId()));
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getGroup(IdGenerator.of(deletedProject.opGroupId()));
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getTarget(IdGenerator.of(deletedProject.targetId()));
});
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testProjectAddGraph.
@Test
public void testProjectAddGraph() {
HugeProject project = makeProject("test_project", "");
AuthManager authManager = graph().authManager();
Id projectId = authManager.createProject(project);
projectId = authManager.projectAddGraphs(projectId, ImmutableSet.of("graph_test"));
Assert.assertNotNull(projectId);
project = authManager.getProject(projectId);
Assert.assertFalse(project.graphs().isEmpty());
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testLogout.
@Test
public void testLogout() throws AuthenticationException {
AuthManager authManager = graph().authManager();
HugeUser user = makeUser("test", StringEncoding.hashPassword("pass"));
@SuppressWarnings("unused") Id userId = authManager.createUser(user);
// Login
String token = authManager.loginUser("test", "pass");
// Logout
Cache<Id, String> tokenCache = Whitebox.getInternalState(authManager, "tokenCache");
Assert.assertTrue(tokenCache.containsKey(IdGenerator.of(token)));
authManager.logoutUser(token);
Assert.assertFalse(tokenCache.containsKey(IdGenerator.of(token)));
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method makeProjectAndAddGraph.
private static Id makeProjectAndAddGraph(HugeGraph graph, String projectName, String graphName) {
HugeProject project = makeProject(projectName, "");
AuthManager authManager = graph.authManager();
Id projectId = authManager.createProject(project);
projectId = authManager.projectAddGraphs(projectId, ImmutableSet.of(graphName));
Assert.assertNotNull(projectId);
return projectId;
}
Aggregations