Search in sources :

Example 26 with AuthManager

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);
    });
}
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 27 with AuthManager

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

Example 28 with AuthManager

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

Example 29 with AuthManager

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

Example 30 with AuthManager

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

Aggregations

AuthManager (com.baidu.hugegraph.auth.AuthManager)46 Test (org.junit.Test)43 Id (com.baidu.hugegraph.backend.id.Id)39 HugeGraph (com.baidu.hugegraph.HugeGraph)36 HugeUser (com.baidu.hugegraph.auth.HugeUser)12 HugeProject (com.baidu.hugegraph.auth.HugeProject)8 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)8 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)7 HugeAccess (com.baidu.hugegraph.auth.HugeAccess)6 HugeBelong (com.baidu.hugegraph.auth.HugeBelong)6 HashMap (java.util.HashMap)6 Date (java.util.Date)5 UserWithRole (com.baidu.hugegraph.auth.UserWithRole)2 HugeResource (com.baidu.hugegraph.auth.HugeResource)1 RolePermission (com.baidu.hugegraph.auth.RolePermission)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 Timed (com.codahale.metrics.annotation.Timed)1 Consumes (jakarta.ws.rs.Consumes)1 PUT (jakarta.ws.rs.PUT)1 Path (jakarta.ws.rs.Path)1