Search in sources :

Example 6 with AfterInvocationManager

use of org.springframework.security.access.intercept.AfterInvocationManager in project spring-security by spring-projects.

the class FilterSecurityInterceptorTests method afterInvocationIsNotInvokedIfExceptionThrown.

@Test
public void afterInvocationIsNotInvokedIfExceptionThrown() throws Exception {
    Authentication token = new TestingAuthenticationToken("Test", "Password", "NOT_USED");
    SecurityContextHolder.getContext().setAuthentication(token);
    FilterInvocation fi = createinvocation();
    FilterChain chain = fi.getChain();
    willThrow(new RuntimeException()).given(chain).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
    given(this.ods.getAttributes(fi)).willReturn(SecurityConfig.createList("MOCK_OK"));
    AfterInvocationManager aim = mock(AfterInvocationManager.class);
    this.interceptor.setAfterInvocationManager(aim);
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> this.interceptor.invoke(fi));
    verifyZeroInteractions(aim);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AfterInvocationManager(org.springframework.security.access.intercept.AfterInvocationManager) Authentication(org.springframework.security.core.Authentication) MockFilterChain(org.springframework.mock.web.MockFilterChain) FilterChain(jakarta.servlet.FilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) FilterInvocation(org.springframework.security.web.FilterInvocation) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)6 AfterInvocationManager (org.springframework.security.access.intercept.AfterInvocationManager)6 FilterChain (jakarta.servlet.FilterChain)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 MockFilterChain (org.springframework.mock.web.MockFilterChain)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 RunAsManager (org.springframework.security.access.intercept.RunAsManager)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 Authentication (org.springframework.security.core.Authentication)2 FilterInvocation (org.springframework.security.web.FilterInvocation)2 MethodInvocation (org.aopalliance.intercept.MethodInvocation)1 RunAsUserToken (org.springframework.security.access.intercept.RunAsUserToken)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1