/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.security.web.util.matcher;

import java.util.Collections;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * Simple strategy to match an <tt>HttpServletRequest</tt>.
 *
 * @author Luke Taylor
 * @author Eddú Meléndez
 * @since 3.0.2
 */
public interface RequestMatcher {

	/**
	 * Decides whether the rule implemented by the strategy matches the supplied request.
	 *
	 * @param request the request to check for a match
	 * @return true if the request matches, false otherwise
	 */
	boolean matches(HttpServletRequest request);

	/**
	 * @since 5.2
	 */
	default MatchResult matcher(HttpServletRequest request) {
		boolean match = matches(request);
		return new MatchResult(match, Collections.emptyMap());
	}

	/**
	 * The result of matching
	 */
	class MatchResult {
		private final boolean match;
		private final Map<String, String> variables;

		MatchResult(boolean match, Map<String, String> variables) {
			this.match = match;
			this.variables = variables;
		}

		public boolean isMatch() {
			return this.match;
		}

		public Map<String, String> getVariables() {
			return this.variables;
		}

		/**
		 * Creates an instance of {@link MatchResult} that is a match with no variables
		 *
		 * @return
		 */
		public static MatchResult match() {
			return new MatchResult(true, Collections.emptyMap());
		}

		/**
		 * Creates an instance of {@link MatchResult} that is a match with the specified variables
		 *
		 * @param variables
		 * @return
		 */
		public static MatchResult match(Map<String, String> variables) {
			return new MatchResult(true, variables);
		}

		/**
		 * Creates an instance of {@link MatchResult} that is not a match.
		 *
		 * @return
		 */
		public static MatchResult notMatch() {
			return new MatchResult(false, Collections.emptyMap());
		}
	}

}

@@ -1206,16 +1206,292 @@
 %09/**%0A%09 *
+ Returns a MatchResult for this RequestMatcher%0A%09 * The default implementation returns  %7B@link Collections#emptyMap()%7D%0A%09 * when %7B@link MatchResult#getVariables()%7D is invoked.%0A%09 *%0A%09 * @return the MatchResult from comparing this RequestMatcher against the HttpServletRequest%0A %09 *
  @since 
@@ -1686,16 +1686,173 @@
 matching
+ against an HttpServletRequest%0A%09 * Contains the status, true or false, of the match and%0A%09 * if present, any variables extracted from the match%0A%09 * @since 5.2
 %0A%09 */%0A%09c
@@ -2076,61 +2076,403 @@
 %0A%0A%09%09
-public boolean isMatch() %7B%0A%09%09%09return this.match;%0A%09%09%7D%0A
+/**%0A%09%09 * @return true if the comparison against the HttpServletRequest produced a successful match%0A%09%09 */%0A%09%09public boolean isMatch() %7B%0A%09%09%09return this.match;%0A%09%09%7D%0A%0A%09%09/**%0A%09%09 * Returns the extracted variable values where the key is the variable name and the value is the variable value%0A%09%09 *%0A%09%09 * @return a map containing key-value pairs representing extracted variable names and variable values%0A%09%09 */
 %0A%09%09p

Add Javadoc