CorsAwareNegotiateSecurityFilter extends NegotiateSecurityFilter implements Filter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { CorsAwareNegotiateSecurityFilter.LOGGER.info("[waffle.servlet.CorsAwareNegotiateSecurityFilter] Filtering"); final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final AuthorizationHeader authorizationHeader = new AuthorizationHeader(httpServletRequest); if (CorsPreFlightCheck.isPreflight(httpServletRequest)) { CorsAwareNegotiateSecurityFilter.LOGGER.info( "[waffle.servlet.CorsAwareNegotiateSecurityFilter] Request is CORS preflight; continue filter chain"); chain.doFilter(request, response); } else if (authorizationHeader.isBearerAuthorizationHeader()) { CorsAwareNegotiateSecurityFilter.LOGGER .info("[waffle.servlet.CorsAwareNegotiateSecurityFilter] Request is Bearer, continue filter chain"); chain.doFilter(request, response); } else { CorsAwareNegotiateSecurityFilter.LOGGER .info("[waffle.servlet.CorsAwareNegotiateSecurityFilter] Request is Not CORS preflight"); super.doFilter(request, response, chain); CorsAwareNegotiateSecurityFilter.LOGGER .info("[waffle.servlet.CorsAwareNegotiateSecurityFilter] Authentication Completed"); } } CorsAwareNegotiateSecurityFilter(); @Override void init(final FilterConfig filterConfig); @Override void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain); @Override void destroy();  }
@Test void doFilterTestCorsPreflightRequest() throws Exception { new Expectations() { { CorsAwareNegotiateSecurityFilterTest.this.preflightRequest.getMethod(); this.result = "OPTIONS"; CorsAwareNegotiateSecurityFilterTest.this.preflightRequest.getHeader("Access-Control-Request-Method"); this.result = "LOGIN"; CorsAwareNegotiateSecurityFilterTest.this.preflightRequest.getHeader("Access-Control-Request-Headers"); this.result = "X-Request-For"; CorsAwareNegotiateSecurityFilterTest.this.preflightRequest.getHeader("Origin"); this.result = "https: } }; this.corsAwareNegotiateSecurityFilter.doFilter(this.preflightRequest, this.preflightResponse, this.chain); new Verifications() { { CorsPreFlightCheck.isPreflight(CorsAwareNegotiateSecurityFilterTest.this.preflightRequest); this.times = 1; CorsAwareNegotiateSecurityFilterTest.this.chain.doFilter( CorsAwareNegotiateSecurityFilterTest.this.preflightRequest, CorsAwareNegotiateSecurityFilterTest.this.preflightResponse); } }; }