Search in sources :

Example 21 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherRequestHCNSTests method mediaAllMatches.

@Test
public void mediaAllMatches() {
    request.addHeader("Accept", MediaType.ALL_VALUE);
    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) Test(org.junit.Test)

Example 22 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherRequestHCNSTests method mediaAllIgnoreMediaTypeAll.

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

Example 23 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherRequestHCNSTests method javadocJsonJsonUseEquals.

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

Example 24 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherRequestHCNSTests method javadocAllJsonUseFalse.

@Test
public void javadocAllJsonUseFalse() {
    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 25 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherTests method mediaAllIgnoreMediaTypeAll.

// ignoreMediaTypeAll
@Test
public void mediaAllIgnoreMediaTypeAll() throws HttpMediaTypeNotAcceptableException {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.ALL));
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
    matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
    assertThat(matcher.matches(request)).isFalse();
}
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