Class RequestHeaderRequestMatcher
- java.lang.Object
-
- org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher
-
- All Implemented Interfaces:
RequestMatcher
public final class RequestHeaderRequestMatcher extends java.lang.Object implements RequestMatcher
ARequestMatcher
that can be used to match request that contain a header with an expected header name and an expected value.For example, the following will match an request that contains a header with the name X-Requested-With no matter what the value is.
RequestMatcher matcher = new RequestHeaderRequestMatcher("X-Requested-With");
Alternatively, the RequestHeaderRequestMatcher can be more precise and require a specific value. For example the following will match on requests with the header name of X-Requested-With with the value of "XMLHttpRequest", but will not match on header name of "X-Requested-With" with the value of "Other".RequestMatcher matcher = new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest");
The value used to compare is the first header value, so in the previous example if the header "X-Requested-With" contains the values "Other" and "XMLHttpRequest", then it will not match.- Since:
- 3.2
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.springframework.security.web.util.matcher.RequestMatcher
RequestMatcher.MatchResult
-
-
Constructor Summary
Constructors Constructor Description RequestHeaderRequestMatcher(java.lang.String expectedHeaderName)
Creates a new instance that will match if a header by the name ofexpectedHeaderName
is present.RequestHeaderRequestMatcher(java.lang.String expectedHeaderName, java.lang.String expectedHeaderValue)
Creates a new instance that will match if a header by the name ofexpectedHeaderName
is present and if theexpectedHeaderValue
is non-null the first value is the same.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
matches(javax.servlet.http.HttpServletRequest request)
Decides whether the rule implemented by the strategy matches the supplied request.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.springframework.security.web.util.matcher.RequestMatcher
matcher
-
-
-
-
Constructor Detail
-
RequestHeaderRequestMatcher
public RequestHeaderRequestMatcher(java.lang.String expectedHeaderName)
Creates a new instance that will match if a header by the name ofexpectedHeaderName
is present. In this instance, the value does not matter.- Parameters:
expectedHeaderName
- the name of the expected header that if present the request will match. Cannot be null.
-
RequestHeaderRequestMatcher
public RequestHeaderRequestMatcher(java.lang.String expectedHeaderName, java.lang.String expectedHeaderValue)
Creates a new instance that will match if a header by the name ofexpectedHeaderName
is present and if theexpectedHeaderValue
is non-null the first value is the same.- Parameters:
expectedHeaderName
- the name of the expected header. Cannot be nullexpectedHeaderValue
- the expected header value or null if the value does not matter
-
-
Method Detail
-
matches
public boolean matches(javax.servlet.http.HttpServletRequest request)
Description copied from interface:RequestMatcher
Decides whether the rule implemented by the strategy matches the supplied request.- Specified by:
matches
in interfaceRequestMatcher
- Parameters:
request
- the request to check for a match- Returns:
- true if the request matches, false otherwise
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-