use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodInvocationPrivilegeEvaluatorTests method allowsAccessUsingCreate.
@Test
public void allowsAccessUsingCreate() throws Exception {
Object object = new TargetObject();
final MethodInvocation mi = MethodInvocationUtils.create(object, "makeLowerCase", "foobar");
MethodInvocationPrivilegeEvaluator mipe = new MethodInvocationPrivilegeEvaluator();
given(this.mds.getAttributes(mi)).willReturn(this.role);
mipe.setSecurityInterceptor(this.interceptor);
mipe.afterPropertiesSet();
assertThat(mipe.isAllowed(mi, this.token)).isTrue();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodInvocationPrivilegeEvaluatorTests method allowsAccessUsingCreateFromClass.
@Test
public void allowsAccessUsingCreateFromClass() {
final MethodInvocation mi = MethodInvocationUtils.createFromClass(new OtherTargetObject(), ITargetObject.class, "makeLowerCase", new Class[] { String.class }, new Object[] { "Hello world" });
MethodInvocationPrivilegeEvaluator mipe = new MethodInvocationPrivilegeEvaluator();
mipe.setSecurityInterceptor(this.interceptor);
given(this.mds.getAttributes(mi)).willReturn(this.role);
assertThat(mipe.isAllowed(mi, this.token)).isTrue();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodInvocationPrivilegeEvaluatorTests method declinesAccessUsingCreateFromClass.
@Test
public void declinesAccessUsingCreateFromClass() {
final MethodInvocation mi = MethodInvocationUtils.createFromClass(new OtherTargetObject(), ITargetObject.class, "makeLowerCase", new Class[] { String.class }, new Object[] { "helloWorld" });
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();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class DelegatingMethodSecurityMetadataSourceTests method returnsDelegateAttributes.
@Test
public void returnsDelegateAttributes() throws Exception {
List sources = new ArrayList();
MethodSecurityMetadataSource delegate = mock(MethodSecurityMetadataSource.class);
ConfigAttribute ca = mock(ConfigAttribute.class);
List attributes = Arrays.asList(ca);
Method toString = String.class.getMethod("toString");
given(delegate.getAttributes(toString, String.class)).willReturn(attributes);
sources.add(delegate);
this.mds = new DelegatingMethodSecurityMetadataSource(sources);
assertThat(this.mds.getMethodSecurityMetadataSources()).isSameAs(sources);
assertThat(this.mds.getAllConfigAttributes().isEmpty()).isTrue();
MethodInvocation mi = new SimpleMethodInvocation("", toString);
assertThat(this.mds.getAttributes(mi)).isSameAs(attributes);
// Exercise the cached case
assertThat(this.mds.getAttributes(mi)).isSameAs(attributes);
assertThat(this.mds.getAttributes(new SimpleMethodInvocation(null, String.class.getMethod("length")))).isEmpty();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class DelegatingMethodSecurityMetadataSourceTests method returnsEmptyListIfDelegateReturnsNull.
@Test
public void returnsEmptyListIfDelegateReturnsNull() throws Exception {
List sources = new ArrayList();
MethodSecurityMetadataSource delegate = mock(MethodSecurityMetadataSource.class);
given(delegate.getAttributes(ArgumentMatchers.<Method>any(), ArgumentMatchers.any(Class.class))).willReturn(null);
sources.add(delegate);
this.mds = new DelegatingMethodSecurityMetadataSource(sources);
assertThat(this.mds.getMethodSecurityMetadataSources()).isSameAs(sources);
assertThat(this.mds.getAllConfigAttributes().isEmpty()).isTrue();
MethodInvocation mi = new SimpleMethodInvocation(null, String.class.getMethod("toString"));
assertThat(this.mds.getAttributes(mi)).isEqualTo(Collections.emptyList());
// Exercise the cached case
assertThat(this.mds.getAttributes(mi)).isEqualTo(Collections.emptyList());
}
Aggregations