@Test(expected = WebApplicationException.class) public void testPostNoXRequestedBy() { AmbariCsrfProtectionFilter filter = new AmbariCsrfProtectionFilter(); ContainerRequest containerRequest = createMock(ContainerRequest.class); InBoundHeaders headers = new InBoundHeaders(); expect(containerRequest.getMethod()).andReturn("POST"); expect(containerRequest.getRequestHeaders()).andReturn(headers); replay(containerRequest); filter.filter(containerRequest); }
@Override public ContainerRequest filter(ContainerRequest containerRequest) { if (!IGNORED_METHODS.contains(containerRequest.getMethod()) && !containerRequest.getRequestHeaders().containsKey(CSRF_HEADER)) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity( JSON_SERIALIZER.serializeError(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, ERROR_MESSAGE)) ).type(MediaType.TEXT_PLAIN_TYPE).build()); } return containerRequest; }
AmbariCsrfProtectionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if (!IGNORED_METHODS.contains(containerRequest.getMethod()) && !containerRequest.getRequestHeaders().containsKey(CSRF_HEADER)) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity( JSON_SERIALIZER.serializeError(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, ERROR_MESSAGE)) ).type(MediaType.TEXT_PLAIN_TYPE).build()); } return containerRequest; } }
AmbariCsrfProtectionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if (!IGNORED_METHODS.contains(containerRequest.getMethod()) && !containerRequest.getRequestHeaders().containsKey(CSRF_HEADER)) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity( JSON_SERIALIZER.serializeError(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, ERROR_MESSAGE)) ).type(MediaType.TEXT_PLAIN_TYPE).build()); } return containerRequest; }  }
AmbariCsrfProtectionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if (!IGNORED_METHODS.contains(containerRequest.getMethod()) && !containerRequest.getRequestHeaders().containsKey(CSRF_HEADER)) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity( JSON_SERIALIZER.serializeError(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, ERROR_MESSAGE)) ).type(MediaType.TEXT_PLAIN_TYPE).build()); } return containerRequest; }  @Override ContainerRequest filter(ContainerRequest containerRequest); }
AmbariCsrfProtectionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if (!IGNORED_METHODS.contains(containerRequest.getMethod()) && !containerRequest.getRequestHeaders().containsKey(CSRF_HEADER)) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity( JSON_SERIALIZER.serializeError(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, ERROR_MESSAGE)) ).type(MediaType.TEXT_PLAIN_TYPE).build()); } return containerRequest; }  @Override ContainerRequest filter(ContainerRequest containerRequest);  }