@Test public void ignoreNoOrigin() throws Exception { when(requestContext.getHeaderString("Origin")).thenReturn(null); domainResponseFilter.filter(requestContext, responseContext); verify(requestContext).getHeaderString("Origin"); }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final String origin = requestContext.getHeaderString("Origin"); if (originMatchUtil.matches(origin)) { MultivaluedMap<String, Object> headers = responseContext.getHeaders(); headers.add("Access-Control-Allow-Origin", origin); headers.add("Access-Control-Allow-Credentials", String.valueOf(corsConfig.getAllowCredentials())); headers.add("Access-Control-Allow-Methods", String.join(",", corsConfig.getAllowedMethods())); final String allowedHeaders; if (corsConfig.getAllowedHeaders() != null) { allowedHeaders = String.join(",", corsConfig.getAllowedHeaders()); } else { allowedHeaders = requestContext.getHeaderString("Access-Control-Request-Headers"); } headers.add("Access-Control-Allow-Headers", allowedHeaders); } }
CorsDomainResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final String origin = requestContext.getHeaderString("Origin"); if (originMatchUtil.matches(origin)) { MultivaluedMap<String, Object> headers = responseContext.getHeaders(); headers.add("Access-Control-Allow-Origin", origin); headers.add("Access-Control-Allow-Credentials", String.valueOf(corsConfig.getAllowCredentials())); headers.add("Access-Control-Allow-Methods", String.join(",", corsConfig.getAllowedMethods())); final String allowedHeaders; if (corsConfig.getAllowedHeaders() != null) { allowedHeaders = String.join(",", corsConfig.getAllowedHeaders()); } else { allowedHeaders = requestContext.getHeaderString("Access-Control-Request-Headers"); } headers.add("Access-Control-Allow-Headers", allowedHeaders); } } }
CorsDomainResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final String origin = requestContext.getHeaderString("Origin"); if (originMatchUtil.matches(origin)) { MultivaluedMap<String, Object> headers = responseContext.getHeaders(); headers.add("Access-Control-Allow-Origin", origin); headers.add("Access-Control-Allow-Credentials", String.valueOf(corsConfig.getAllowCredentials())); headers.add("Access-Control-Allow-Methods", String.join(",", corsConfig.getAllowedMethods())); final String allowedHeaders; if (corsConfig.getAllowedHeaders() != null) { allowedHeaders = String.join(",", corsConfig.getAllowedHeaders()); } else { allowedHeaders = requestContext.getHeaderString("Access-Control-Request-Headers"); } headers.add("Access-Control-Allow-Headers", allowedHeaders); } } CorsDomainResponseFilter(CrossDomainConfig corsConfig); }
CorsDomainResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final String origin = requestContext.getHeaderString("Origin"); if (originMatchUtil.matches(origin)) { MultivaluedMap<String, Object> headers = responseContext.getHeaders(); headers.add("Access-Control-Allow-Origin", origin); headers.add("Access-Control-Allow-Credentials", String.valueOf(corsConfig.getAllowCredentials())); headers.add("Access-Control-Allow-Methods", String.join(",", corsConfig.getAllowedMethods())); final String allowedHeaders; if (corsConfig.getAllowedHeaders() != null) { allowedHeaders = String.join(",", corsConfig.getAllowedHeaders()); } else { allowedHeaders = requestContext.getHeaderString("Access-Control-Request-Headers"); } headers.add("Access-Control-Allow-Headers", allowedHeaders); } } CorsDomainResponseFilter(CrossDomainConfig corsConfig); @Override void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext); }
CorsDomainResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final String origin = requestContext.getHeaderString("Origin"); if (originMatchUtil.matches(origin)) { MultivaluedMap<String, Object> headers = responseContext.getHeaders(); headers.add("Access-Control-Allow-Origin", origin); headers.add("Access-Control-Allow-Credentials", String.valueOf(corsConfig.getAllowCredentials())); headers.add("Access-Control-Allow-Methods", String.join(",", corsConfig.getAllowedMethods())); final String allowedHeaders; if (corsConfig.getAllowedHeaders() != null) { allowedHeaders = String.join(",", corsConfig.getAllowedHeaders()); } else { allowedHeaders = requestContext.getHeaderString("Access-Control-Request-Headers"); } headers.add("Access-Control-Allow-Headers", allowedHeaders); } } CorsDomainResponseFilter(CrossDomainConfig corsConfig); @Override void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext);  }