001/* 002 * Copyright 2002-2016 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 */ 016package org.springframework.web.reactive.result.view; 017 018import java.util.Map; 019 020import org.springframework.lang.Nullable; 021import org.springframework.web.server.ServerWebExchange; 022 023/** 024 * A contract for inspecting and potentially modifying request data values such 025 * as URL query parameters or form field values before they are rendered by a 026 * view or before a redirect. 027 * 028 * <p>Implementations may use this contract for example as part of a solution 029 * to provide data integrity, confidentiality, protection against cross-site 030 * request forgery (CSRF), and others or for other tasks such as automatically 031 * adding a hidden field to all forms and URLs. 032 * 033 * <p>View technologies that support this contract can obtain an instance to 034 * delegate to via {@link RequestContext#getRequestDataValueProcessor()}. 035 * 036 * @author Rossen Stoyanchev 037 * @since 5.0 038 */ 039public interface RequestDataValueProcessor { 040 041 /** 042 * Invoked when a new form action is rendered. 043 * @param exchange the current exchange 044 * @param action the form action 045 * @param httpMethod the form HTTP method 046 * @return the action to use, possibly modified 047 */ 048 String processAction(ServerWebExchange exchange, String action, String httpMethod); 049 050 /** 051 * Invoked when a form field value is rendered. 052 * @param exchange the current exchange 053 * @param name the form field name 054 * @param value the form field value 055 * @param type the form field type ("text", "hidden", etc.) 056 * @return the form field value to use, possibly modified 057 */ 058 String processFormFieldValue(ServerWebExchange exchange, String name, String value, String type); 059 060 /** 061 * Invoked after all form fields have been rendered. 062 * @param exchange the current exchange 063 * @return additional hidden form fields to be added, or {@code null} 064 */ 065 @Nullable 066 Map<String, String> getExtraHiddenFields(ServerWebExchange exchange); 067 068 /** 069 * Invoked when a URL is about to be rendered or redirected to. 070 * @param exchange the current exchange 071 * @param url the URL value 072 * @return the URL to use, possibly modified 073 */ 074 String processUrl(ServerWebExchange exchange, String url); 075 076}