@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(); } LoginContext loginContext = getLoginContextFromUserPrincipal( principal ); UserManager userManager = userManagerSupplier.getUserManager( loginContext.subject(), false ); try { User user = userManager.getUser( username ); return output.ok( new AuthorizationRepresentation( user ) ); } catch ( InvalidArgumentsException e ) { return output.notFound(); } }
@Test public void shouldChangePasswordAndReturnSuccess() throws Exception { // Given HttpServletRequest req = mock( HttpServletRequest.class ); when( req.getUserPrincipal() ).thenReturn( neo4jPrinciple ); OutputFormat outputFormat = new EntityOutputFormat( new JsonFormat(), new URI( "http://www.example.com" ), null ); UserService userService = new UserService( userManagerSupplier, new JsonFormat(), outputFormat ); // When Response response = userService.setPassword( "neo4j", req, "{ \"password\" : \"test\" }" ); // Then assertThat( response.getStatus(), equalTo( 200 ) ); userManagerSupplier.getUserManager().getUser( "neo4j" ).credentials().matchesPassword( "test" ); }
@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(); } LoginContext loginContext = getLoginContextFromUserPrincipal( principal ); UserManager userManager = userManagerSupplier.getUserManager( loginContext.subject(), false ); try { User user = userManager.getUser( username ); return output.ok( new AuthorizationRepresentation( user ) ); } catch ( InvalidArgumentsException e ) { return output.notFound(); } }