Search in sources :

Example 6 with TargetObject

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();
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) ITargetObject(org.springframework.security.ITargetObject) TargetObject(org.springframework.security.TargetObject)

Example 7 with TargetObject

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();
}
Also used : Method(java.lang.reflect.Method) MethodSecurityMetadataSource(org.springframework.security.access.method.MethodSecurityMetadataSource) TargetObject(org.springframework.security.TargetObject) Test(org.junit.Test)

Example 8 with TargetObject

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();
}
Also used : Method(java.lang.reflect.Method) MethodSecurityMetadataSource(org.springframework.security.access.method.MethodSecurityMetadataSource) TargetObject(org.springframework.security.TargetObject) Test(org.junit.Test)

Example 9 with TargetObject

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);
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Method(java.lang.reflect.Method) TargetObject(org.springframework.security.TargetObject)

Aggregations

TargetObject (org.springframework.security.TargetObject)9 Test (org.junit.Test)7 Method (java.lang.reflect.Method)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)3 ITargetObject (org.springframework.security.ITargetObject)3 OtherTargetObject (org.springframework.security.OtherTargetObject)2 MethodInvocationPrivilegeEvaluator (org.springframework.security.access.intercept.MethodInvocationPrivilegeEvaluator)2 MethodSecurityMetadataSource (org.springframework.security.access.method.MethodSecurityMetadataSource)2 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)1