@Test public void deniesTheHostIfNotRegistered() throws Exception { given(req.getHeader("Origin")).willReturn("http: CorsConfig allowedHosts = new CorsConfig(ImmutableSet.of("http: CorsFilter underTest = new CorsFilter(allowedHosts); underTest.doFilter(req, res, chain); verify(res, times(0)).setHeader("Access-Control-Allow-Origin", "http: }
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String requestOrigin = request.getHeader("Origin"); if (isHostAllowed(requestOrigin)) { response.setHeader("Access-Control-Allow-Origin", requestOrigin); } response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", hosts.getMethods()); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, X-Requested-With"); chain.doFilter(req, res); }
CorsFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String requestOrigin = request.getHeader("Origin"); if (isHostAllowed(requestOrigin)) { response.setHeader("Access-Control-Allow-Origin", requestOrigin); } response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", hosts.getMethods()); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, X-Requested-With"); chain.doFilter(req, res); } }
CorsFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String requestOrigin = request.getHeader("Origin"); if (isHostAllowed(requestOrigin)) { response.setHeader("Access-Control-Allow-Origin", requestOrigin); } response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", hosts.getMethods()); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, X-Requested-With"); chain.doFilter(req, res); } @Autowired  CorsFilter(CorsConfig hosts); }
CorsFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String requestOrigin = request.getHeader("Origin"); if (isHostAllowed(requestOrigin)) { response.setHeader("Access-Control-Allow-Origin", requestOrigin); } response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", hosts.getMethods()); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, X-Requested-With"); chain.doFilter(req, res); } @Autowired  CorsFilter(CorsConfig hosts); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); @Override void destroy(); }
CorsFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String requestOrigin = request.getHeader("Origin"); if (isHostAllowed(requestOrigin)) { response.setHeader("Access-Control-Allow-Origin", requestOrigin); } response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", hosts.getMethods()); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, X-Requested-With"); chain.doFilter(req, res); } @Autowired  CorsFilter(CorsConfig hosts); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); @Override void destroy();  }