use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class OAuth2ResourceServerConfigurer method registerDefaultEntryPoint.
private void registerDefaultEntryPoint(H http) {
ExceptionHandlingConfigurer<H> exceptionHandling = http.getConfigurer(ExceptionHandlingConfigurer.class);
if (exceptionHandling != null) {
ContentNegotiationStrategy contentNegotiationStrategy = http.getSharedObject(ContentNegotiationStrategy.class);
if (contentNegotiationStrategy == null) {
contentNegotiationStrategy = new HeaderContentNegotiationStrategy();
}
MediaTypeRequestMatcher restMatcher = new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_XML, MediaType.MULTIPART_FORM_DATA, MediaType.TEXT_XML);
restMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
MediaTypeRequestMatcher allMatcher = new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.ALL);
allMatcher.setUseEquals(true);
RequestMatcher notHtmlMatcher = new NegatedRequestMatcher(new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.TEXT_HTML));
RequestMatcher restNotHtmlMatcher = new AndRequestMatcher(Arrays.<RequestMatcher>asList(notHtmlMatcher, restMatcher));
RequestMatcher preferredMatcher = new OrRequestMatcher(Arrays.asList(this.requestMatcher, X_REQUESTED_WITH, restNotHtmlMatcher, allMatcher));
exceptionHandling.defaultAuthenticationEntryPointFor(this.authenticationEntryPoint, preferredMatcher);
}
}
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 spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method mediaAllAndTextHtmlIgnoreMediaTypeAll.
@Test
public void mediaAllAndTextHtmlIgnoreMediaTypeAll() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.ALL, MediaType.TEXT_HTML));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
assertThat(matcher.matches(request)).isTrue();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherRequestHCNSTests method javadocJsonJsonIgnoreAll.
@Test
public void javadocJsonJsonIgnoreAll() {
request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_JSON);
matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
assertThat(matcher.matches(request)).isTrue();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherRequestHCNSTests method javadocAllJsonIgnoreAll.
@Test
public void javadocAllJsonIgnoreAll() {
request.addHeader("Accept", MediaType.ALL_VALUE);
MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_JSON);
matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
assertThat(matcher.matches(request)).isFalse();
}
Aggregations