@Test public void doFilter() throws IOException, ServletException { DawgCorsFilter filter = new DawgCorsFilter(); filter.doFilter(req, res, chain); verify(res).setHeader("Access-Control-Allow-Origin", "*"); verify(res).setHeader("Access-Control-Allow-Methods","PUT, POST, GET, OPTIONS, DELETE"); verify(res).setHeader("Access-Control-Max-Age", "3600"); verify(res).setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Accept"); verify(chain).doFilter(req, res); }
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { LOGGER.debug("Applying CORS headers to http response"); HttpServletResponse response = (HttpServletResponse) res; String allowOrigin = null; if (this.domainWhitelist != null) { HttpServletRequest request = (HttpServletRequest) req; String origin = request.getHeader("Origin"); if (origin != null) { try { String originHost = new URI(origin).getHost(); for (String domain : domainWhitelist) { if (originHost.endsWith(domain)) { allowOrigin = origin; break; } } } catch (URISyntaxException e) { e.printStackTrace(); } } } else { allowOrigin = "*"; } if (allowOrigin != null) { response.setHeader("Access-Control-Allow-Origin", allowOrigin); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods","PUT, POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Accept"); } chain.doFilter(req, res); }
DawgCorsFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { LOGGER.debug("Applying CORS headers to http response"); HttpServletResponse response = (HttpServletResponse) res; String allowOrigin = null; if (this.domainWhitelist != null) { HttpServletRequest request = (HttpServletRequest) req; String origin = request.getHeader("Origin"); if (origin != null) { try { String originHost = new URI(origin).getHost(); for (String domain : domainWhitelist) { if (originHost.endsWith(domain)) { allowOrigin = origin; break; } } } catch (URISyntaxException e) { e.printStackTrace(); } } } else { allowOrigin = "*"; } if (allowOrigin != null) { response.setHeader("Access-Control-Allow-Origin", allowOrigin); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods","PUT, POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Accept"); } chain.doFilter(req, res); } }
DawgCorsFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { LOGGER.debug("Applying CORS headers to http response"); HttpServletResponse response = (HttpServletResponse) res; String allowOrigin = null; if (this.domainWhitelist != null) { HttpServletRequest request = (HttpServletRequest) req; String origin = request.getHeader("Origin"); if (origin != null) { try { String originHost = new URI(origin).getHost(); for (String domain : domainWhitelist) { if (originHost.endsWith(domain)) { allowOrigin = origin; break; } } } catch (URISyntaxException e) { e.printStackTrace(); } } } else { allowOrigin = "*"; } if (allowOrigin != null) { response.setHeader("Access-Control-Allow-Origin", allowOrigin); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods","PUT, POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Accept"); } chain.doFilter(req, res); } DawgCorsFilter();  DawgCorsFilter(Set<String> domainWhitelist); }
DawgCorsFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { LOGGER.debug("Applying CORS headers to http response"); HttpServletResponse response = (HttpServletResponse) res; String allowOrigin = null; if (this.domainWhitelist != null) { HttpServletRequest request = (HttpServletRequest) req; String origin = request.getHeader("Origin"); if (origin != null) { try { String originHost = new URI(origin).getHost(); for (String domain : domainWhitelist) { if (originHost.endsWith(domain)) { allowOrigin = origin; break; } } } catch (URISyntaxException e) { e.printStackTrace(); } } } else { allowOrigin = "*"; } if (allowOrigin != null) { response.setHeader("Access-Control-Allow-Origin", allowOrigin); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods","PUT, POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Accept"); } chain.doFilter(req, res); } DawgCorsFilter();  DawgCorsFilter(Set<String> domainWhitelist); void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
DawgCorsFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { LOGGER.debug("Applying CORS headers to http response"); HttpServletResponse response = (HttpServletResponse) res; String allowOrigin = null; if (this.domainWhitelist != null) { HttpServletRequest request = (HttpServletRequest) req; String origin = request.getHeader("Origin"); if (origin != null) { try { String originHost = new URI(origin).getHost(); for (String domain : domainWhitelist) { if (originHost.endsWith(domain)) { allowOrigin = origin; break; } } } catch (URISyntaxException e) { e.printStackTrace(); } } } else { allowOrigin = "*"; } if (allowOrigin != null) { response.setHeader("Access-Control-Allow-Origin", allowOrigin); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods","PUT, POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Accept"); } chain.doFilter(req, res); } DawgCorsFilter();  DawgCorsFilter(Set<String> domainWhitelist); void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); void init(FilterConfig filterConfig); void destroy();  }