use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testCreateGroup.
@Test
public void testCreateGroup() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
HugeGroup group = makeGroup("group1");
Id id = authManager.createGroup(group);
group = authManager.getGroup(id);
Assert.assertEquals("group1", group.name());
Assert.assertEquals(null, group.description());
Assert.assertEquals(group.create(), group.update());
Assert.assertEquals(ImmutableMap.of("group_name", "group1", "group_create", group.create(), "group_update", group.update(), "group_creator", "admin", "id", group.id()), group.asMap());
group = makeGroup("group2");
group.description("something");
id = authManager.createGroup(group);
group = authManager.getGroup(id);
Assert.assertEquals("group2", group.name());
Assert.assertEquals("something", group.description());
Assert.assertEquals(group.create(), group.update());
HashMap<String, Object> expected = new HashMap<>();
expected.putAll(ImmutableMap.of("group_name", "group2", "group_description", "something", "group_creator", "admin"));
expected.putAll(ImmutableMap.of("group_create", group.create(), "group_update", group.update(), "id", group.id()));
Assert.assertEquals(expected, group.asMap());
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testListGroups.
@Test
public void testListGroups() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createGroup(makeGroup("group1"));
Id id2 = authManager.createGroup(makeGroup("group2"));
List<HugeGroup> groups = authManager.listGroups(ImmutableList.of(id1, id2));
Assert.assertEquals(2, groups.size());
Assert.assertEquals("group1", groups.get(0).name());
Assert.assertEquals("group2", groups.get(1).name());
groups = authManager.listGroups(ImmutableList.of(id1, id2, id2));
Assert.assertEquals(3, groups.size());
Assert.assertEquals("group1", groups.get(0).name());
Assert.assertEquals("group2", groups.get(1).name());
Assert.assertEquals("group2", groups.get(2).name());
groups = authManager.listGroups(ImmutableList.of(id1, id2, IdGenerator.of("fake")));
Assert.assertEquals(2, groups.size());
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testLogin.
@Test
public void testLogin() throws AuthenticationException {
AuthManager authManager = graph().authManager();
HugeUser user = makeUser("test", StringEncoding.hashPassword("pass"));
authManager.createUser(user);
// Login
authManager.loginUser("test", "pass");
// Invalid username or password
Assert.assertThrows(AuthenticationException.class, () -> {
authManager.loginUser("huge", "graph");
}, e -> {
Assert.assertContains("Incorrect username or password", e.getMessage());
});
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testDeleteUser.
@Test
public void testDeleteUser() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createUser(makeUser("tom", "pass1"));
Id id2 = authManager.createUser(makeUser("james", "pass2"));
Assert.assertEquals(2, authManager.listAllUsers(-1).size());
HugeUser user = authManager.deleteUser(id1);
Assert.assertEquals("tom", user.name());
Assert.assertEquals(1, authManager.listAllUsers(-1).size());
user = authManager.deleteUser(id2);
Assert.assertEquals("james", user.name());
Assert.assertEquals(0, authManager.listAllUsers(-1).size());
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testListAccess.
@Test
public void testListAccess() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id group = authManager.createGroup(makeGroup("group1"));
Id target1 = authManager.createTarget(makeTarget("graph1", "url1"));
Id target2 = authManager.createTarget(makeTarget("graph2", "url2"));
Id id1 = authManager.createAccess(makeAccess(group, target1, HugePermission.READ));
Id id2 = authManager.createAccess(makeAccess(group, target2, HugePermission.READ));
List<HugeAccess> access = authManager.listAccess(ImmutableList.of(id1, id2));
Assert.assertEquals(2, access.size());
Assert.assertEquals(group, access.get(0).source());
Assert.assertEquals(group, access.get(1).source());
Assert.assertEquals(target1, access.get(0).target());
Assert.assertEquals(target2, access.get(1).target());
access = authManager.listAccess(ImmutableList.of(id1, id2, id2));
Assert.assertEquals(3, access.size());
access = authManager.listAccess(ImmutableList.of(id1, id2, IdGenerator.of("fake")));
Assert.assertEquals(2, access.size());
access = authManager.listAccessByGroup(group, -1);
Assert.assertEquals(2, access.size());
Assert.assertEquals(group, access.get(0).source());
Assert.assertEquals(group, access.get(1).source());
access = authManager.listAccessByTarget(target1, -1);
Assert.assertEquals(1, access.size());
Assert.assertEquals(group, access.get(0).source());
Assert.assertEquals(target1, access.get(0).target());
access = authManager.listAccessByTarget(target2, -1);
Assert.assertEquals(1, access.size());
Assert.assertEquals(group, access.get(0).source());
Assert.assertEquals(target2, access.get(0).target());
}
Aggregations