use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method makeTarget.
private static HugeTarget makeTarget(String name, String graph, String url, List<HugeResource> ress) {
HugeTarget target = new HugeTarget(name, graph, url, ress);
target.creator("admin");
return target;
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method testDeleteTarget.
@Test
public void testDeleteTarget() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createTarget(makeTarget("target1", "url1"));
Id id2 = authManager.createTarget(makeTarget("target2", "url2"));
Assert.assertEquals(2, authManager.listAllTargets(-1).size());
HugeTarget target = authManager.deleteTarget(id1);
Assert.assertEquals("target1", target.name());
Assert.assertEquals(1, authManager.listAllTargets(-1).size());
target = authManager.deleteTarget(id2);
Assert.assertEquals("target2", target.name());
Assert.assertEquals(0, authManager.listAllTargets(-1).size());
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
authManager.deleteTarget(user);
});
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method clearAll.
@After
public void clearAll() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
for (HugeUser user : authManager.listAllUsers(-1)) {
authManager.deleteUser(user.id());
}
for (HugeGroup group : authManager.listAllGroups(-1)) {
authManager.deleteGroup(group.id());
}
for (HugeTarget target : authManager.listAllTargets(-1)) {
authManager.deleteTarget(target.id());
}
for (HugeProject project : authManager.listAllProject(-1)) {
if (!CollectionUtils.isEmpty(project.graphs())) {
authManager.projectRemoveGraphs(project.id(), project.graphs());
}
authManager.deleteProject(project.id());
}
Assert.assertEquals(0, authManager.listAllAccess(-1).size());
Assert.assertEquals(0, authManager.listAllBelong(-1).size());
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method testListAllTargets.
@Test
public void testListAllTargets() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
authManager.createTarget(makeTarget("target1", "url1"));
authManager.createTarget(makeTarget("target2", "url1"));
List<HugeTarget> targets = authManager.listAllTargets(-1);
Assert.assertEquals(2, targets.size());
Assert.assertEquals(ImmutableSet.of("target1", "target2"), ImmutableSet.of(targets.get(0).name(), targets.get(1).name()));
Assert.assertEquals(0, authManager.listAllTargets(0).size());
Assert.assertEquals(1, authManager.listAllTargets(1).size());
Assert.assertEquals(2, authManager.listAllTargets(2).size());
Assert.assertEquals(2, authManager.listAllTargets(3).size());
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class RolePermissionTest method testHugeResourceFilterUser.
@Test
public void testHugeResourceFilterUser() {
HugeResource all = HugeResource.ALL;
// user
ResourceObject<?> r3 = ResourceObject.of("g1", ResourceType.USER_GROUP, NameObject.ANY);
Assert.assertFalse(all.filter(r3));
HugeResource user = new HugeResource(ResourceType.USER_GROUP, HugeResource.ANY, null);
Assert.assertTrue(user.filter(r3));
ResourceObject<?> r4 = ResourceObject.of("g1", new HugeUser("fake"));
Assert.assertTrue(user.filter(r4));
HugeResource user2 = new HugeResource(ResourceType.USER_GROUP, "bj-.*", null);
Assert.assertTrue(user2.filter(r3));
Assert.assertFalse(user2.filter(r4));
HugeResource user3 = new HugeResource(ResourceType.USER_GROUP, "fa.*", null);
Assert.assertTrue(user3.filter(r3));
Assert.assertTrue(user3.filter(r4));
ResourceObject<?> r5 = ResourceObject.of("g1", new HugeTarget("g", ""));
Assert.assertFalse(user.filter(r5));
HugeResource root = new HugeResource(ResourceType.ROOT, HugeResource.ANY, null);
Assert.assertTrue(root.filter(r3));
Assert.assertTrue(root.filter(r4));
Assert.assertTrue(root.filter(r5));
}
Aggregations