use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method collectionPreFilteringIsSuccessful.
@Test
public void collectionPreFilteringIsSuccessful() throws Exception {
List arg = createCollectionArg("joe", "bob", "sam");
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe' or filterObject == 'sam')", "collection", "permitAll")));
assertThat(arg).containsExactly("joe", "sam");
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method ruleDefinedInAClassMethodIsApplied.
@Test
public void ruleDefinedInAClassMethodIsApplied() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAString(), "joe");
assertThat(this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "T(org.springframework.security.access.expression.method.SecurityRules).isJoe(#argument)")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method arraysCannotBePrefiltered.
@Test
public void arraysCannotBePrefiltered() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray(), createArrayArg("sam", "joe"));
assertThatIllegalArgumentException().isThrownBy(() -> this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "someArray", null))));
}
use of org.aopalliance.intercept.MethodInvocation 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.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodInvocationPrivilegeEvaluatorTests method declinesAccessUsingCreate.
@Test
public void declinesAccessUsingCreate() {
Object object = new TargetObject();
final MethodInvocation mi = MethodInvocationUtils.create(object, "makeLowerCase", "foobar");
MethodInvocationPrivilegeEvaluator mipe = new MethodInvocationPrivilegeEvaluator();
mipe.setSecurityInterceptor(this.interceptor);
given(this.mds.getAttributes(mi)).willReturn(this.role);
willThrow(new AccessDeniedException("rejected")).given(this.adm).decide(this.token, mi, this.role);
assertThat(mipe.isAllowed(mi, this.token)).isFalse();
}
Aggregations