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; 020 021import javax.servlet.http.HttpServletRequest; 022import javax.servlet.http.HttpServletResponse; 023 024import org.springframework.lang.Nullable; 025 026/** 027 * A strategy that takes a request and a {@link CorsConfiguration} and updates 028 * the response. 029 * 030 * <p>This component is not concerned with how a {@code CorsConfiguration} is 031 * selected but rather takes follow-up actions such as applying CORS validation 032 * checks and either rejecting the response or adding CORS headers to the 033 * response. 034 * 035 * @author Sebastien Deleuze 036 * @author Rossen Stoyanchev 037 * @since 4.2 038 * @see <a href="https://www.w3.org/TR/cors/">CORS W3C recommendation</a> 039 * @see org.springframework.web.servlet.handler.AbstractHandlerMapping#setCorsProcessor 040 */ 041public interface CorsProcessor { 042 043 /** 044 * Process a request given a {@code CorsConfiguration}. 045 * @param configuration the applicable CORS configuration (possibly {@code null}) 046 * @param request the current request 047 * @param response the current response 048 * @return {@code false} if the request is rejected, {@code true} otherwise 049 */ 050 boolean processRequest(@Nullable CorsConfiguration configuration, HttpServletRequest request, 051 HttpServletResponse response) throws IOException; 052 053}