use of org.springframework.security.access.intercept.AfterInvocationManager in project spring-security by spring-projects.
the class AspectJMethodSecurityInterceptorTests method afterInvocationManagerIsNotInvokedIfExceptionIsRaised.
@Test
public void afterInvocationManagerIsNotInvokedIfExceptionIsRaised() {
this.token.setAuthenticated(true);
SecurityContextHolder.getContext().setAuthentication(this.token);
AfterInvocationManager aim = mock(AfterInvocationManager.class);
this.interceptor.setAfterInvocationManager(aim);
given(this.aspectJCallback.proceedWithObject()).willThrow(new RuntimeException());
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
verifyZeroInteractions(aim);
}
use of org.springframework.security.access.intercept.AfterInvocationManager in project spring-security by spring-projects.
the class MethodSecurityInterceptorTests method intitalizationRejectsAfterInvocationManagerThatDoesNotSupportMethodInvocation.
@Test
public void intitalizationRejectsAfterInvocationManagerThatDoesNotSupportMethodInvocation() throws Exception {
final AfterInvocationManager aim = mock(AfterInvocationManager.class);
given(aim.supports(MethodInvocation.class)).willReturn(false);
this.interceptor.setAfterInvocationManager(aim);
assertThatIllegalArgumentException().isThrownBy(() -> this.interceptor.afterPropertiesSet());
}
use of org.springframework.security.access.intercept.AfterInvocationManager in project spring-security by spring-projects.
the class MethodSecurityInterceptorTests method afterInvocationManagerIsNotInvokedIfExceptionIsRaised.
@Test
public void afterInvocationManagerIsNotInvokedIfExceptionIsRaised() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class);
this.token.setAuthenticated(true);
SecurityContextHolder.getContext().setAuthentication(this.token);
mdsReturnsUserRole();
AfterInvocationManager aim = mock(AfterInvocationManager.class);
this.interceptor.setAfterInvocationManager(aim);
given(mi.proceed()).willThrow(new Throwable());
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> this.interceptor.invoke(mi));
verifyZeroInteractions(aim);
}
use of org.springframework.security.access.intercept.AfterInvocationManager in project spring-security by spring-projects.
the class MethodSecurityInterceptorTests method gettersReturnExpectedData.
@Test
public void gettersReturnExpectedData() {
RunAsManager runAs = mock(RunAsManager.class);
AfterInvocationManager aim = mock(AfterInvocationManager.class);
this.interceptor.setRunAsManager(runAs);
this.interceptor.setAfterInvocationManager(aim);
assertThat(this.interceptor.getAccessDecisionManager()).isEqualTo(this.adm);
assertThat(this.interceptor.getRunAsManager()).isEqualTo(runAs);
assertThat(this.interceptor.getAuthenticationManager()).isEqualTo(this.authman);
assertThat(this.interceptor.getSecurityMetadataSource()).isEqualTo(this.mds);
assertThat(this.interceptor.getAfterInvocationManager()).isEqualTo(aim);
}
use of org.springframework.security.access.intercept.AfterInvocationManager in project spring-security by spring-projects.
the class FilterSecurityInterceptorTests method finallyInvocationIsInvokedIfExceptionThrown.
// SEC-1967
@Test
@SuppressWarnings("unchecked")
public void finallyInvocationIsInvokedIfExceptionThrown() throws Exception {
SecurityContext ctx = SecurityContextHolder.getContext();
Authentication token = new TestingAuthenticationToken("Test", "Password", "NOT_USED");
token.setAuthenticated(true);
ctx.setAuthentication(token);
RunAsManager runAsManager = mock(RunAsManager.class);
given(runAsManager.buildRunAs(eq(token), any(), anyCollection())).willReturn(new RunAsUserToken("key", "someone", "creds", token.getAuthorities(), token.getClass()));
this.interceptor.setRunAsManager(runAsManager);
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));
// Check we've changed back
assertThat(SecurityContextHolder.getContext()).isSameAs(ctx);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(token);
}
Aggregations