Search in sources :

Example 31 with RequestMatcher

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

the class EndpointRequestTests method excludeByClassShouldNotMatchExcluded.

@Test
void excludeByClassShouldNotMatchExcluded() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint().excluding(FooEndpoint.class, BazServletEndpoint.class);
    List<ExposableEndpoint<?>> endpoints = new ArrayList<>();
    endpoints.add(mockEndpoint(EndpointId.of("foo"), "foo"));
    endpoints.add(mockEndpoint(EndpointId.of("bar"), "bar"));
    endpoints.add(mockEndpoint(EndpointId.of("baz"), "baz"));
    PathMappedEndpoints pathMappedEndpoints = new PathMappedEndpoints("/actuator", () -> endpoints);
    assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/foo");
    assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/baz");
    assertMatcher(matcher).matches("/actuator/bar");
    assertMatcher(matcher).matches("/actuator");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) ExposableEndpoint(org.springframework.boot.actuate.endpoint.ExposableEndpoint) ArrayList(java.util.ArrayList) PathMappedEndpoints(org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints) Test(org.junit.jupiter.api.Test)

Example 32 with RequestMatcher

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

the class EndpointRequestTests method toEndpointClassShouldNotMatchOtherPath.

@Test
void toEndpointClassShouldNotMatchOtherPath() {
    RequestMatcher matcher = EndpointRequest.to(FooEndpoint.class);
    assertMatcher(matcher).doesNotMatch("/actuator/bar");
    assertMatcher(matcher).doesNotMatch("/actuator");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 33 with RequestMatcher

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

the class EndpointRequestTests method toAnyEndpointShouldMatchEndpointPath.

@Test
void toAnyEndpointShouldMatchEndpointPath() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
    assertMatcher(matcher, "/actuator").matches("/actuator/foo");
    assertMatcher(matcher, "/actuator").matches("/actuator/foo/zoo/");
    assertMatcher(matcher, "/actuator").matches("/actuator/bar");
    assertMatcher(matcher, "/actuator").matches("/actuator/bar/baz");
    assertMatcher(matcher, "/actuator").matches("/actuator");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 34 with RequestMatcher

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

the class EndpointRequestTests method excludeByIdShouldNotMatchLinksIfExcluded.

@Test
void excludeByIdShouldNotMatchLinksIfExcluded() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint().excludingLinks().excluding("foo");
    assertMatcher(matcher).doesNotMatch("/actuator/foo");
    assertMatcher(matcher).doesNotMatch("/actuator");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 35 with RequestMatcher

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

the class EndpointRequestTests method excludeLinksShouldNotMatchBasePathIfEmptyAndExcluded.

@Test
void excludeLinksShouldNotMatchBasePathIfEmptyAndExcluded() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint().excludingLinks();
    RequestMatcherAssert assertMatcher = assertMatcher(matcher, "");
    assertMatcher.doesNotMatch("/");
    assertMatcher.matches("/foo");
    assertMatcher.matches("/bar");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Aggregations

RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)85 Test (org.junit.jupiter.api.Test)40 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)27 LinkedHashMap (java.util.LinkedHashMap)16 AndRequestMatcher (org.springframework.security.web.util.matcher.AndRequestMatcher)14 NegatedRequestMatcher (org.springframework.security.web.util.matcher.NegatedRequestMatcher)12 RequestHeaderRequestMatcher (org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher)12 ArrayList (java.util.ArrayList)11 AuthenticationEntryPoint (org.springframework.security.web.AuthenticationEntryPoint)10 OrRequestMatcher (org.springframework.security.web.util.matcher.OrRequestMatcher)10 MediaTypeRequestMatcher (org.springframework.security.web.util.matcher.MediaTypeRequestMatcher)9 Collection (java.util.Collection)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 ConfigAttribute (org.springframework.security.access.ConfigAttribute)7 AnyRequestMatcher (org.springframework.security.web.util.matcher.AnyRequestMatcher)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 DelegatingAuthenticationEntryPoint (org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint)6 ContentNegotiationStrategy (org.springframework.web.accept.ContentNegotiationStrategy)6 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)6