Search in sources :

Example 11 with HugeTarget

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;
}
Also used : HugeTarget(com.baidu.hugegraph.auth.HugeTarget)

Example 12 with HugeTarget

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);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Test(org.junit.Test)

Example 13 with HugeTarget

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeProject(com.baidu.hugegraph.auth.HugeProject) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) HugeUser(com.baidu.hugegraph.auth.HugeUser) After(org.junit.After)

Example 14 with HugeTarget

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Test(org.junit.Test)

Example 15 with HugeTarget

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));
}
Also used : HugeResource(com.baidu.hugegraph.auth.HugeResource) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) HugeUser(com.baidu.hugegraph.auth.HugeUser) Test(org.junit.Test)

Aggregations

HugeTarget (com.baidu.hugegraph.auth.HugeTarget)15 HugeGraph (com.baidu.hugegraph.HugeGraph)12 AuthManager (com.baidu.hugegraph.auth.AuthManager)8 Test (org.junit.Test)8 Id (com.baidu.hugegraph.backend.id.Id)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 HugeUser (com.baidu.hugegraph.auth.HugeUser)2 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)1 HugeProject (com.baidu.hugegraph.auth.HugeProject)1 HugeResource (com.baidu.hugegraph.auth.HugeResource)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1