use of org.springframework.security.util.SimpleMethodInvocation 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");
when(delegate.getAttributes(toString, String.class)).thenReturn(attributes);
sources.add(delegate);
mds = new DelegatingMethodSecurityMetadataSource(sources);
assertThat(mds.getMethodSecurityMetadataSources()).isSameAs(sources);
assertThat(mds.getAllConfigAttributes().isEmpty()).isTrue();
MethodInvocation mi = new SimpleMethodInvocation("", toString);
assertThat(mds.getAttributes(mi)).isSameAs(attributes);
// Exercise the cached case
assertThat(mds.getAttributes(mi)).isSameAs(attributes);
assertThat(mds.getAttributes(new SimpleMethodInvocation(null, String.class.getMethod("length")))).isEmpty();
;
}
use of org.springframework.security.util.SimpleMethodInvocation 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);
when(delegate.getAttributes(Matchers.<Method>any(), Matchers.any(Class.class))).thenReturn(null);
sources.add(delegate);
mds = new DelegatingMethodSecurityMetadataSource(sources);
assertThat(mds.getMethodSecurityMetadataSources()).isSameAs(sources);
assertThat(mds.getAllConfigAttributes().isEmpty()).isTrue();
MethodInvocation mi = new SimpleMethodInvocation(null, String.class.getMethod("toString"));
assertThat(mds.getAttributes(mi)).isEqualTo(Collections.emptyList());
// Exercise the cached case
assertThat(mds.getAttributes(mi)).isEqualTo(Collections.emptyList());
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method nullNamedFilterTargetIsRejected.
@Test(expected = IllegalArgumentException.class)
public void nullNamedFilterTargetIsRejected() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), new Object[] { null });
am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collection", null)));
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method incorrectFilterTargetNameIsRejected.
@Test(expected = IllegalArgumentException.class)
public void incorrectFilterTargetNameIsRejected() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), createCollectionArg("joe", "bob"));
am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collcetion", null)));
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method hasRoleExpressionAllowsUserWithRole.
@Test
public void hasRoleExpressionAllowsUserWithRole() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
assertThat(am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "hasRole('blah')")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
Aggregations