use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testUpdateBelong.
@Test
public void testUpdateBelong() throws InterruptedException {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id user = authManager.createUser(makeUser("tom", "pass1"));
Id group = authManager.createGroup(makeGroup("group1"));
HugeBelong belong = makeBelong(user, group);
belong.description("description1");
Id id = authManager.createBelong(belong);
belong = authManager.getBelong(id);
Assert.assertEquals(user, belong.source());
Assert.assertEquals(group, belong.target());
Assert.assertEquals("description1", belong.description());
Assert.assertEquals(belong.create(), belong.update());
Date oldUpdateTime = belong.update();
Thread.sleep(1L);
belong.description("description2");
authManager.updateBelong(belong);
HugeBelong belong2 = authManager.getBelong(id);
Assert.assertEquals(user, belong.source());
Assert.assertEquals(group, belong.target());
Assert.assertEquals("description2", belong.description());
Assert.assertEquals(oldUpdateTime, belong2.create());
Assert.assertNotEquals(oldUpdateTime, belong2.update());
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id group2 = authManager.createGroup(makeGroup("group2"));
HugeBelong belong3 = makeBelong(user, group2);
authManager.updateBelong(belong3);
}, e -> {
Assert.assertContains("Can't save belong", e.getMessage());
Assert.assertContains("that not exists", e.getMessage());
});
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testListAllAccess.
@Test
public void testListAllAccess() {
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"));
authManager.createAccess(makeAccess(group, target1, HugePermission.READ));
authManager.createAccess(makeAccess(group, target2, HugePermission.READ));
List<HugeAccess> access = authManager.listAllAccess(-1);
Assert.assertEquals(2, access.size());
Assert.assertEquals(ImmutableSet.of(target1, target2), ImmutableSet.of(access.get(0).target(), access.get(1).target()));
Assert.assertEquals(0, authManager.listAllAccess(0).size());
Assert.assertEquals(1, authManager.listAllAccess(1).size());
Assert.assertEquals(2, authManager.listAllAccess(2).size());
Assert.assertEquals(2, authManager.listAllAccess(3).size());
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testDeleteGroup.
@Test
public void testDeleteGroup() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createGroup(makeGroup("group1"));
Id id2 = authManager.createGroup(makeGroup("group2"));
Assert.assertEquals(2, authManager.listAllGroups(-1).size());
HugeGroup group = authManager.deleteGroup(id1);
Assert.assertEquals("group1", group.name());
Assert.assertEquals(1, authManager.listAllGroups(-1).size());
group = authManager.deleteGroup(id2);
Assert.assertEquals("group2", group.name());
Assert.assertEquals(0, authManager.listAllGroups(-1).size());
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
authManager.deleteGroup(user);
});
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testDeleteAccess.
@Test
public void testDeleteAccess() {
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));
Assert.assertEquals(2, authManager.listAllAccess(-1).size());
HugeAccess access = authManager.deleteAccess(id1);
Assert.assertEquals(target1, access.target());
Assert.assertEquals(1, authManager.listAllAccess(-1).size());
Assert.assertEquals(1, authManager.listAllAccess(2).size());
access = authManager.deleteAccess(id2);
Assert.assertEquals(target2, access.target());
Assert.assertEquals(0, authManager.listAllAccess(-1).size());
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
Id belong = authManager.createBelong(makeBelong(user, group));
authManager.deleteAccess(belong);
});
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testValidateUserByNameAndPassword.
@Test
public void testValidateUserByNameAndPassword() {
AuthManager authManager = graph().authManager();
HugeUser user = makeUser("test", StringEncoding.hashPassword("pass"));
Id userId = authManager.createUser(user);
UserWithRole userWithRole;
userWithRole = authManager.validateUser("test", "pass");
Assert.assertEquals(userId, userWithRole.userId());
Assert.assertEquals("test", userWithRole.username());
Assert.assertEquals("{\"roles\":{}}", userWithRole.role().toJson());
// Error case
userWithRole = authManager.validateUser("huge", "graph");
Assert.assertNull(userWithRole.userId());
Assert.assertEquals("huge", userWithRole.username());
Assert.assertNull(userWithRole.role());
}
Aggregations