001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.cors; 018 019import java.io.IOException; 020import javax.servlet.http.HttpServletRequest; 021import javax.servlet.http.HttpServletResponse; 022 023/** 024 * A strategy that takes a request and a {@link CorsConfiguration} and updates 025 * the response. 026 * 027 * <p>This component is not concerned with how a {@code CorsConfiguration} is 028 * selected but rather takes follow-up actions such as applying CORS validation 029 * checks and either rejecting the response or adding CORS headers to the 030 * response. 031 * 032 * @author Sebastien Deleuze 033 * @author Rossen Stoyanchev 034 * @since 4.2 035 * @see <a href="https://www.w3.org/TR/cors/">CORS W3C recommendation</a> 036 * @see org.springframework.web.servlet.handler.AbstractHandlerMapping#setCorsProcessor 037 */ 038public interface CorsProcessor { 039 040 /** 041 * Process a request given a {@code CorsConfiguration}. 042 * @param configuration the applicable CORS configuration (possibly {@code null}) 043 * @param request the current request 044 * @param response the current response 045 * @return {@code false} if the request is rejected, {@code true} otherwise 046 */ 047 boolean processRequest(CorsConfiguration configuration, HttpServletRequest request, 048 HttpServletResponse response) throws IOException; 049 050}