// Path: src/spring-cloud-cloudfoundry-service-broker/src/main/java/org/springframework/cloud/servicebroker/interceptor/BrokerApiVersionInterceptor.java
// public class BrokerApiVersionInterceptor extends HandlerInterceptorAdapter {
// 
// 	private final BrokerApiVersion version;
// 
// 	public BrokerApiVersionInterceptor() {
// 		this(null);
// 	}
// 
// 	public BrokerApiVersionInterceptor(BrokerApiVersion version) {
// 		this.version = version;
// 	}
// 
// 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
// 			Object handler) throws ServiceBrokerApiVersionException {
// 		if (version != null && !anyVersionAllowed()) {
// 			String apiVersion = request.getHeader(version.getBrokerApiVersionHeader());
// 			if (!version.getApiVersion().equals(apiVersion)) {
// 				throw new ServiceBrokerApiVersionException(version.getApiVersion(), apiVersion);
// 			} 
// 		}
// 		return true;
// 	}
// 
// 	private boolean anyVersionAllowed() {
// 		return BrokerApiVersion.API_VERSION_ANY.equals(version.getApiVersion());
// 	}
// 
// }
// 
// Path: src/spring-cloud-cloudfoundry-service-broker/src/main/java/org/springframework/cloud/servicebroker/model/BrokerApiVersion.java
// @Getter
// @ToString
// @EqualsAndHashCode
// public class BrokerApiVersion {
// 
// 	public final static String DEFAULT_API_VERSION_HEADER = "X-Broker-Api-Version";
// 	public final static String API_VERSION_ANY = "*";
// 	public final static String API_VERSION_CURRENT = "2.8";
// 
// 	/**
// 	 * The name of the HTTP header field expected to contain the API version of the service broker client.
// 	 */
// 	private final String brokerApiVersionHeader;
// 
// 	/**
// 	 * The version of the broker API supported by the broker. A value of <code>null</code> or
// 	 * <code>API_VERSION_ANY</code> will disable API version validation.
// 	 */
// 	private final String apiVersion;
// 
// 	public BrokerApiVersion(String brokerApiVersionHeader, String apiVersion) {
// 		this.brokerApiVersionHeader = brokerApiVersionHeader;
// 		this.apiVersion = apiVersion;
// 	}
// 
// 	public BrokerApiVersion(String apiVersion) {
// 		this(DEFAULT_API_VERSION_HEADER, apiVersion);
// 	}
// 
// 	public BrokerApiVersion() {
// 		this(DEFAULT_API_VERSION_HEADER, API_VERSION_ANY);
// 	}
// }


import org.springframework.cloud.servicebroker.interceptor.BrokerApiVersionInterceptor;
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
package org.springframework.cloud.servicebroker.config;


@Configuration
@EnableWebMvc
public class BrokerApiVersionConfig extends WebMvcConfigurerAdapter {

	@Autowired
	private BrokerApiVersion brokerApiVersion;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
// Path: src/spring-cloud-cloudfoundry-service-broker/src/main/java/org/springframework/cloud/servicebroker/interceptor/BrokerApiVersionInterceptor.java
// public class BrokerApiVersionInterceptor extends HandlerInterceptorAdapter {
// 
// 	private final BrokerApiVersion version;
// 
// 	public BrokerApiVersionInterceptor() {
// 		this(null);
// 	}
// 
// 	public BrokerApiVersionInterceptor(BrokerApiVersion version) {
// 		this.version = version;
// 	}
// 
// 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
// 			Object handler) throws ServiceBrokerApiVersionException {
// 		if (version != null && !anyVersionAllowed()) {
// 			String apiVersion = request.getHeader(version.getBrokerApiVersionHeader());
// 			if (!version.getApiVersion().equals(apiVersion)) {
// 				throw new ServiceBrokerApiVersionException(version.getApiVersion(), apiVersion);
// 			} 
// 		}
// 		return true;
// 	}
// 
// 	private boolean anyVersionAllowed() {
// 		return BrokerApiVersion.API_VERSION_ANY.equals(version.getApiVersion());
// 	}
// 
// }
// 
// Path: src/spring-cloud-cloudfoundry-service-broker/src/main/java/org/springframework/cloud/servicebroker/model/BrokerApiVersion.java
// @Getter
// @ToString
// @EqualsAndHashCode
// public class BrokerApiVersion {
// 
// 	public final static String DEFAULT_API_VERSION_HEADER = "X-Broker-Api-Version";
// 	public final static String API_VERSION_ANY = "*";
// 	public final static String API_VERSION_CURRENT = "2.8";
// 
// 	/**
// 	 * The name of the HTTP header field expected to contain the API version of the service broker client.
// 	 */
// 	private final String brokerApiVersionHeader;
// 
// 	/**
// 	 * The version of the broker API supported by the broker. A value of <code>null</code> or
// 	 * <code>API_VERSION_ANY</code> will disable API version validation.
// 	 */
// 	private final String apiVersion;
// 
// 	public BrokerApiVersion(String brokerApiVersionHeader, String apiVersion) {
// 		this.brokerApiVersionHeader = brokerApiVersionHeader;
// 		this.apiVersion = apiVersion;
// 	}
// 
// 	public BrokerApiVersion(String apiVersion) {
// 		this(DEFAULT_API_VERSION_HEADER, apiVersion);
// 	}
// 
// 	public BrokerApiVersion() {
// 		this(DEFAULT_API_VERSION_HEADER, API_VERSION_ANY);
// 	}
// }


// Path: src/spring-cloud-cloudfoundry-service-broker/src/main/java/org/springframework/cloud/servicebroker/config/BrokerApiVersionConfig.java
import org.springframework.cloud.servicebroker.interceptor.BrokerApiVersionInterceptor;
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

package org.springframework.cloud.servicebroker.config;


@Configuration
@EnableWebMvc
public class BrokerApiVersionConfig extends WebMvcConfigurerAdapter {

	@Autowired
	private BrokerApiVersion brokerApiVersion;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new BrokerApiVersionInterceptor(brokerApiVersion)).addPathPatterns("/v2/**");