Search in sources :

Example 1 with IgnoredRequestCustomizer

use of org.springframework.boot.autoconfigure.security.IgnoredRequestCustomizer in project spring-boot by spring-projects.

the class CloudFoundryActuatorAutoConfigurationTests method cloudFoundryPathsIgnoredBySpringSecurity.

@Test
public void cloudFoundryPathsIgnoredBySpringSecurity() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id");
    this.context.refresh();
    IgnoredRequestCustomizer customizer = (IgnoredRequestCustomizer) this.context.getBean("cloudFoundryIgnoredRequestCustomizer");
    IgnoredRequestConfigurer configurer = mock(IgnoredRequestConfigurer.class);
    customizer.customize(configurer);
    ArgumentCaptor<RequestMatcher> requestMatcher = ArgumentCaptor.forClass(RequestMatcher.class);
    verify(configurer).requestMatchers(requestMatcher.capture());
    RequestMatcher matcher = requestMatcher.getValue();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/cloudfoundryapplication/my-path");
    assertThat(matcher.matches(request)).isTrue();
    request.setServletPath("/some-other-path");
    assertThat(matcher.matches(request)).isFalse();
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IgnoredRequestCustomizer(org.springframework.boot.autoconfigure.security.IgnoredRequestCustomizer) IgnoredRequestConfigurer(org.springframework.security.config.annotation.web.builders.WebSecurity.IgnoredRequestConfigurer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 IgnoredRequestCustomizer (org.springframework.boot.autoconfigure.security.IgnoredRequestCustomizer)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 IgnoredRequestConfigurer (org.springframework.security.config.annotation.web.builders.WebSecurity.IgnoredRequestConfigurer)1 RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)1