use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method multipleMediaType.
@Test
public void multipleMediaType() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.APPLICATION_XHTML_XML, MediaType.TEXT_HTML));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_ATOM_XML, MediaType.TEXT_HTML);
assertThat(matcher.matches(request)).isTrue();
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_XHTML_XML, MediaType.APPLICATION_JSON);
assertThat(matcher.matches(request)).isTrue();
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON);
assertThat(matcher.matches(request)).isFalse();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method useEqualsResolveTextAllMatchesTextPlain.
// useEquals
@Test
public void useEqualsResolveTextAllMatchesTextPlain() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text", "*")));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_PLAIN);
matcher.setUseEquals(true);
assertThat(matcher.matches(request)).isFalse();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method resolveTextAllMatchesTextPlain.
@Test
public void resolveTextAllMatchesTextPlain() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text", "*")));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_PLAIN);
assertThat(matcher.matches(request)).isTrue();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project coffeenet-starter by coffeenet.
the class IntegrationCoffeeNetWebSecurityConfigurerAdapter method mediaTypeRequestMatcher.
private static MediaTypeRequestMatcher mediaTypeRequestMatcher(final ContentNegotiationStrategy contentNegotiationStrategy) {
ContentNegotiationStrategy negotiationStrategy = contentNegotiationStrategy;
if (negotiationStrategy == null) {
negotiationStrategy = new HeaderContentNegotiationStrategy();
}
MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, APPLICATION_XHTML_XML, new MediaType("image", "*"), TEXT_HTML, TEXT_PLAIN);
matcher.setIgnoredMediaTypes(singleton(ALL));
return matcher;
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project ma-core-public by infiniteautomation.
the class MangoSecurityConfiguration method createBrowserHtmlRequestMatcher.
/**
* Internal method to create a static matcher
* @return
*/
private static RequestMatcher createBrowserHtmlRequestMatcher() {
ContentNegotiationStrategy contentNegotiationStrategy = contentNegotiationStrategy();
MediaTypeRequestMatcher mediaMatcher = new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.APPLICATION_XHTML_XML, MediaType.TEXT_HTML);
mediaMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
RequestMatcher notXRequestedWith = new NegatedRequestMatcher(new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest"));
return new AndRequestMatcher(Arrays.asList(notXRequestedWith, mediaMatcher));
}
Aggregations