WebUtil { public static RequestMatcher buildCsrfRequestMatcher( Collection<CsrfProtectionDefinition> csrfProtectionDefinitions ) { List<RequestMatcher> requestMatchers = new ArrayList<>(); for ( CsrfProtectionDefinition csrfProtectionDefinition : csrfProtectionDefinitions ) { collectRequestMatchers( requestMatchers, csrfProtectionDefinition ); } return requestMatchers.size() > 0 ? new OrRequestMatcher( requestMatchers ) : null; }  static void setCorsResponseHeaders( HttpServletRequest request, HttpServletResponse response ); static void setCorsResponseHeaders( HttpServletRequest request, HttpServletResponse response,
                                             Map<String, List<String>> corsHeadersConfiguration ); static CsrfProtectionDefinition parseXmlCsrfProtectionDefinition( Element csrfProtectionElem ); static RequestMatcher buildCsrfRequestMatcher( Collection<CsrfProtectionDefinition> csrfProtectionDefinitions ); static final String CORS_EXPOSE_HEADERS_HEADER; }
@Test public void testBuildCsrfRequestMatcherEmptyList() { CsrfProtectionDefinition protectionDefinition = new CsrfProtectionDefinition(); Collection<CsrfProtectionDefinition> protectionDefinitions = Collections.emptyList(); RequestMatcher result = WebUtil.buildCsrfRequestMatcher( protectionDefinitions ); assertNull( result ); }
@Test public void testBuildCsrfRequestMatcherOneDefinitionWithNullRequestMatchers() { CsrfProtectionDefinition protectionDefinition = new CsrfProtectionDefinition(); Collection<CsrfProtectionDefinition> protectionDefinitions = Collections.singletonList( protectionDefinition ); RequestMatcher result = WebUtil.buildCsrfRequestMatcher( protectionDefinitions ); assertNull( result ); }
@Test public void testBuildCsrfRequestMatcherOneDefinitionWithEmptyRequestMatchers() { CsrfProtectionDefinition protectionDefinition = new CsrfProtectionDefinition(); protectionDefinition.setProtectedRequestMatchers( Collections.emptyList() ); Collection<CsrfProtectionDefinition> protectionDefinitions = Collections.singletonList( protectionDefinition ); RequestMatcher result = WebUtil.buildCsrfRequestMatcher( protectionDefinitions ); assertNull( result ); }