Search in sources :

Example 51 with RequestMatcher

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

the class EndpointRequestTests method endpointRequestMatcherShouldUseCustomRequestMatcherProvider.

@Test
void endpointRequestMatcherShouldUseCustomRequestMatcherProvider() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
    RequestMatcher mockRequestMatcher = (request) -> false;
    RequestMatcherAssert assertMatcher = assertMatcher(matcher, mockPathMappedEndpoints(""), (pattern) -> mockRequestMatcher);
    assertMatcher.doesNotMatch("/foo");
    assertMatcher.doesNotMatch("/bar");
}
Also used : PathMappedEndpoint(org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) ExposableEndpoint(org.springframework.boot.actuate.endpoint.ExposableEndpoint) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WebApplicationContext(org.springframework.web.context.WebApplicationContext) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) ServletEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint) RequestMatcherProvider(org.springframework.boot.autoconfigure.security.servlet.RequestMatcherProvider) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) AssertDelegateTarget(org.assertj.core.api.AssertDelegateTarget) BDDMockito.given(org.mockito.BDDMockito.given) WebEndpointProperties(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties) Operation(org.springframework.boot.actuate.endpoint.Operation) PathMappedEndpoints(org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints) MockServletContext(org.springframework.mock.web.MockServletContext) Mockito.mock(org.mockito.Mockito.mock) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 52 with RequestMatcher

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

the class EndpointRequestTests method toEndpointIdShouldNotMatchOtherPath.

@Test
void toEndpointIdShouldNotMatchOtherPath() {
    RequestMatcher matcher = EndpointRequest.to("foo");
    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 53 with RequestMatcher

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

the class EndpointRequestTests method toAnyEndpointWhenBasePathIsEmptyShouldNotMatchLinks.

@Test
void toAnyEndpointWhenBasePathIsEmptyShouldNotMatchLinks() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
    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)

Example 54 with RequestMatcher

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

the class EndpointRequestTests method toAnyEndpointShouldNotMatchOtherPath.

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

Example 55 with RequestMatcher

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

the class EndpointRequestTests method toAnyEndpointShouldMatchEndpointPathWithTrailingSlash.

@Test
void toAnyEndpointShouldMatchEndpointPathWithTrailingSlash() {
    RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
    assertMatcher(matcher, "/actuator").matches("/actuator/foo/");
    assertMatcher(matcher, "/actuator").matches("/actuator/bar/");
    assertMatcher(matcher, "/actuator").matches("/actuator/");
}
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