Search in sources :

Example 1 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherTests method resolveTextPlainMatchesTextAll.

@Test
public void resolveTextPlainMatchesTextAll() throws HttpMediaTypeNotAcceptableException {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text", "*"));
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MediaType(org.springframework.http.MediaType) MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Test(org.junit.Test)

Example 2 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherTests method useEqualsWithCustomMediaType.

@Test
public void useEqualsWithCustomMediaType() throws HttpMediaTypeNotAcceptableException {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text", "unique")));
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text", "unique"));
    matcher.setUseEquals(true);
    assertThat(matcher.matches(request)).isTrue();
}
Also used : MediaType(org.springframework.http.MediaType) MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Test(org.junit.Test)

Example 3 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherTests method useEqualsResolveTextPlainMatchesTextAll.

@Test
public void useEqualsResolveTextPlainMatchesTextAll() throws HttpMediaTypeNotAcceptableException {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text", "*"));
    matcher.setUseEquals(true);
    assertThat(matcher.matches(request)).isFalse();
}
Also used : MediaType(org.springframework.http.MediaType) MediaTypeRequestMatcher(org.springframework.security.web.util.matcher.MediaTypeRequestMatcher) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Test(org.junit.Test)

Example 4 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherTests method useEqualsSame.

@Test
public void useEqualsSame() throws HttpMediaTypeNotAcceptableException {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));
    matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_PLAIN);
    matcher.setUseEquals(true);
    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)

Example 5 with MediaTypeRequestMatcher

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

the class MediaTypeRequestMatcherTests method mediaAllQ08AndTextPlainIgnoreMediaTypeAll.

@Test
public void mediaAllQ08AndTextPlainIgnoreMediaTypeAll() throws HttpMediaTypeNotAcceptableException {
    when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.parseMediaType("*/*;q=0.8")));
    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