Search in sources :

Example 6 with MediaTypeRequestMatcher

use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.

the class MediaTypeRequestMatcherRequestHCNSTests method javadocJsonJson.

// JavaDoc
@Test
public void javadocJsonJson() {
    request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
    MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_JSON);
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) Test(org.junit.Test)

Example 7 with MediaTypeRequestMatcher

use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.

the class MediaTypeRequestMatcherRequestHCNSTests method mediaAllAndTextHtmlIgnoreMediaTypeAll.

@Test
public void mediaAllAndTextHtmlIgnoreMediaTypeAll() {
    request.addHeader("Accept", MediaType.ALL_VALUE + "," + MediaType.TEXT_HTML_VALUE);
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
    matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) Test(org.junit.Test)

Example 8 with MediaTypeRequestMatcher

use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.

the class MediaTypeRequestMatcherRequestHCNSTests method javadocAllJsonUseEquals.

@Test
public void javadocAllJsonUseEquals() {
    request.addHeader("Accept", MediaType.ALL_VALUE);
    MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_JSON);
    matcher.setUseEquals(true);
    assertThat(matcher.matches(request)).isFalse();
}
Also used : MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) Test(org.junit.Test)

Example 9 with MediaTypeRequestMatcher

use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.

the class MediaTypeRequestMatcherRequestHCNSTests method javadocAllJson.

@Test
public void javadocAllJson() {
    request.addHeader("Accept", MediaType.ALL_VALUE);
    MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_JSON);
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) Test(org.junit.Test)

Example 10 with MediaTypeRequestMatcher

use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.

the class MediaTypeRequestMatcherTests method mediaAllMatches.

@Test
public void mediaAllMatches() throws Exception {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.ALL));
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
    assertThat(matcher.matches(request)).isTrue();
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_XHTML_XML);
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Test(org.junit.Test)

Aggregations

MediaTypeRequestMatcher (org.springframework.security.web.util.matcher.MediaTypeRequestMatcher)33 Test (org.junit.Test)21 ContentNegotiationStrategy (org.springframework.web.accept.ContentNegotiationStrategy)12 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)12 MediaType (org.springframework.http.MediaType)11 NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)11 NegatedRequestMatcher (org.springframework.security.web.util.matcher.NegatedRequestMatcher)7 RequestHeaderRequestMatcher (org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher)7 AndRequestMatcher (org.springframework.security.web.util.matcher.AndRequestMatcher)6 RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)6 HttpSecurity (org.springframework.security.config.annotation.web.builders.HttpSecurity)3 OrRequestMatcher (org.springframework.security.web.util.matcher.OrRequestMatcher)3 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)2 HttpStatusEntryPoint (org.springframework.security.web.authentication.HttpStatusEntryPoint)1 LoginUrlAuthenticationEntryPoint (org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint)1 BasicAuthenticationEntryPoint (org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint)1