Search in sources :

Example 11 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class MultiRealmAuthManagerTest method defaultUserShouldHaveCorrectPermissions.

@Test
public void defaultUserShouldHaveCorrectPermissions() throws Throwable {
    // Given
    manager.start();
    setMockAuthenticationStrategyResult("neo4j", "neo4j", AuthenticationResult.SUCCESS);
    // When
    SecurityContext securityContext = manager.login(authToken("neo4j", "neo4j"));
    userManager.setUserPassword("neo4j", "1234", false);
    securityContext.subject().logout();
    setMockAuthenticationStrategyResult("neo4j", "1234", AuthenticationResult.SUCCESS);
    securityContext = manager.login(authToken("neo4j", "1234"));
    // Then
    assertTrue(securityContext.mode().allowsReads());
    assertTrue(securityContext.mode().allowsWrites());
    assertTrue(securityContext.mode().allowsSchemaWrites());
}
Also used : SecurityContext(org.neo4j.kernel.api.security.SecurityContext) Test(org.junit.Test)

Example 12 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class MultiRealmAuthManagerTest method userWithArchitectRoleShouldHaveCorrectPermissions.

@Test
public void userWithArchitectRoleShouldHaveCorrectPermissions() throws Throwable {
    // Given
    createTestUsers();
    manager.start();
    // When
    SecurityContext securityContext = manager.login(authToken("trinity", "abc123"));
    // Then
    assertTrue(securityContext.mode().allowsReads());
    assertTrue(securityContext.mode().allowsWrites());
    assertTrue(securityContext.mode().allowsSchemaWrites());
}
Also used : SecurityContext(org.neo4j.kernel.api.security.SecurityContext) Test(org.junit.Test)

Example 13 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class MultiRealmAuthManagerTest method userWithReaderRoleShouldHaveCorrectPermissions.

@Test
public void userWithReaderRoleShouldHaveCorrectPermissions() throws Throwable {
    // Given
    createTestUsers();
    manager.start();
    // When
    SecurityContext securityContext = manager.login(authToken("neo", "abc123"));
    // Then
    assertTrue(securityContext.mode().allowsReads());
    assertFalse(securityContext.mode().allowsWrites());
    assertFalse(securityContext.mode().allowsSchemaWrites());
}
Also used : SecurityContext(org.neo4j.kernel.api.security.SecurityContext) Test(org.junit.Test)

Example 14 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class UserService method getUser.

@GET
@Path("/{username}")
public Response getUser(@PathParam("username") String username, @Context HttpServletRequest req) {
    Principal principal = req.getUserPrincipal();
    if (principal == null || !principal.getName().equals(username)) {
        return output.notFound();
    }
    SecurityContext securityContext = getSecurityContextFromUserPrincipal(principal);
    UserManager userManager = userManagerSupplier.getUserManager(securityContext);
    try {
        User user = userManager.getUser(username);
        return output.ok(new AuthorizationRepresentation(user));
    } catch (InvalidArgumentsException e) {
        return output.notFound();
    }
}
Also used : User(org.neo4j.kernel.impl.security.User) UserManager(org.neo4j.kernel.api.security.UserManager) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) AuthorizationRepresentation(org.neo4j.server.rest.repr.AuthorizationRepresentation) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException) AuthorizedRequestWrapper.getSecurityContextFromUserPrincipal(org.neo4j.server.rest.dbms.AuthorizedRequestWrapper.getSecurityContextFromUserPrincipal) Principal(java.security.Principal) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 15 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class SecurityContextDescriptionTest method shouldMakeNiceDescriptionAuthDisabledAndRestricted.

@Test
public void shouldMakeNiceDescriptionAuthDisabledAndRestricted() throws Throwable {
    SecurityContext disabled = SecurityContext.AUTH_DISABLED;
    SecurityContext restricted = disabled.withMode(new RestrictedAccessMode(disabled.mode(), AccessMode.Static.READ));
    assertThat(restricted.description(), equalTo("AUTH_DISABLED with FULL restricted to READ"));
}
Also used : RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) Test(org.junit.Test)

Aggregations

SecurityContext (org.neo4j.kernel.api.security.SecurityContext)33 Test (org.junit.Test)20 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)4 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 IOException (java.io.IOException)2 Principal (java.security.Principal)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 InOrder (org.mockito.InOrder)2 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)2 Transaction (org.neo4j.graphdb.Transaction)2 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)2 Statement (org.neo4j.kernel.api.Statement)2 InvalidArgumentsException (org.neo4j.kernel.api.exceptions.InvalidArgumentsException)2 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)2 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2