@Test public void nonLocalhostTest() throws Exception { LocalhostFilter filter = mockWithRemoteAddress("192.168.1.1"); ContainerRequestContext context = mockContainerRequestContext("test"); ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class); filter.filter(context); verify(context).abortWith(captor.capture()); assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), captor.getValue().getStatus()); }
@Override public void filter(final ContainerRequestContext context) { if (request == null) { return; } String path = context.getUriInfo().getPath(); if (allowedPaths.contains(path)) { return; } if (!localAddresses.contains(request.getRemoteAddr())) { context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); } }
LocalhostFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext context) { if (request == null) { return; } String path = context.getUriInfo().getPath(); if (allowedPaths.contains(path)) { return; } if (!localAddresses.contains(request.getRemoteAddr())) { context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); } } }
LocalhostFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext context) { if (request == null) { return; } String path = context.getUriInfo().getPath(); if (allowedPaths.contains(path)) { return; } if (!localAddresses.contains(request.getRemoteAddr())) { context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); } }  }
LocalhostFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext context) { if (request == null) { return; } String path = context.getUriInfo().getPath(); if (allowedPaths.contains(path)) { return; } if (!localAddresses.contains(request.getRemoteAddr())) { context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); } }  @PostConstruct void init(); @Override void filter(final ContainerRequestContext context); }
LocalhostFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext context) { if (request == null) { return; } String path = context.getUriInfo().getPath(); if (allowedPaths.contains(path)) { return; } if (!localAddresses.contains(request.getRemoteAddr())) { context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); } }  @PostConstruct void init(); @Override void filter(final ContainerRequestContext context);  }