use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class MethodSecurityInterceptorTests method createTarget.
private void createTarget(boolean useMock) {
realTarget = useMock ? mock(ITargetObject.class) : new TargetObject();
ProxyFactory pf = new ProxyFactory(realTarget);
pf.addAdvice(interceptor);
advisedTarget = (ITargetObject) pf.getProxy();
}
use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class MethodSecurityMetadataSourceAdvisorTests method testAdvisorReturnsTrueWhenMethodInvocationIsDefined.
@Test
public void testAdvisorReturnsTrueWhenMethodInvocationIsDefined() throws Exception {
Class<TargetObject> clazz = TargetObject.class;
Method method = clazz.getMethod("countLength", new Class[] { String.class });
MethodSecurityMetadataSource mds = mock(MethodSecurityMetadataSource.class);
when(mds.getAttributes(method, clazz)).thenReturn(SecurityConfig.createList("ROLE_A"));
MethodSecurityMetadataSourceAdvisor advisor = new MethodSecurityMetadataSourceAdvisor("", mds, "");
assertThat(advisor.getPointcut().getMethodMatcher().matches(method, clazz)).isTrue();
}
use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class MethodSecurityMetadataSourceAdvisorTests method testAdvisorReturnsFalseWhenMethodInvocationNotDefined.
// ~ Methods
// ========================================================================================================
@Test
public void testAdvisorReturnsFalseWhenMethodInvocationNotDefined() throws Exception {
Class<TargetObject> clazz = TargetObject.class;
Method method = clazz.getMethod("makeLowerCase", new Class[] { String.class });
MethodSecurityMetadataSource mds = mock(MethodSecurityMetadataSource.class);
when(mds.getAttributes(method, clazz)).thenReturn(null);
MethodSecurityMetadataSourceAdvisor advisor = new MethodSecurityMetadataSourceAdvisor("", mds, "");
assertThat(advisor.getPointcut().getMethodMatcher().matches(method, clazz)).isFalse();
}
use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class ContextPropagatingRemoteInvocationTests method getRemoteInvocation.
private ContextPropagatingRemoteInvocation getRemoteInvocation() throws Exception {
Class<TargetObject> clazz = TargetObject.class;
Method method = clazz.getMethod("makeLowerCase", new Class[] { String.class });
MethodInvocation mi = new SimpleMethodInvocation(new TargetObject(), method, "SOME_STRING");
ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
}
Aggregations