use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class ContextPropagatingRemoteInvocationTests method testNullContextHolderDoesNotCauseInvocationProblems.
@Test
public void testNullContextHolderDoesNotCauseInvocationProblems() throws Exception {
// just to be explicit
SecurityContextHolder.clearContext();
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
// unnecessary, but for
SecurityContextHolder.clearContext();
// explicitness
assertThat(remoteInvocation.invoke(new TargetObject())).isEqualTo("some_string Authentication empty");
}
use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class ContextPropagatingRemoteInvocationTests method testNormalOperation.
@Test
public void testNormalOperation() throws Exception {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
// Set to null, as ContextPropagatingRemoteInvocation already obtained
// a copy and nulling is necessary to ensure the Context delivered by
// ContextPropagatingRemoteInvocation is used on server-side
SecurityContextHolder.clearContext();
// The result from invoking the TargetObject should contain the
// Authentication class delivered via the SecurityContextHolder
assertThat(remoteInvocation.invoke(new TargetObject())).isEqualTo("some_string org.springframework.security.authentication.UsernamePasswordAuthenticationToken false");
}
use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class AspectJMethodSecurityInterceptorTests method adapterHoldsCorrectData.
@Test
public void adapterHoldsCorrectData() throws Exception {
TargetObject to = new TargetObject();
Method m = ClassUtils.getMethodIfAvailable(TargetObject.class, "countLength", new Class[] { String.class });
when(joinPoint.getTarget()).thenReturn(to);
when(joinPoint.getArgs()).thenReturn(new Object[] { "Hi" });
MethodInvocationAdapter mia = new MethodInvocationAdapter(joinPoint);
assertThat(mia.getArguments()[0]).isEqualTo("Hi");
assertThat(mia.getStaticPart()).isEqualTo(m);
assertThat(mia.getMethod()).isEqualTo(m);
assertThat(mia.getThis()).isSameAs(to);
}
use of org.springframework.security.TargetObject 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();
when(mds.getAttributes(mi)).thenReturn(role);
mipe.setSecurityInterceptor(interceptor);
mipe.afterPropertiesSet();
assertThat(mipe.isAllowed(mi, token)).isTrue();
}
use of org.springframework.security.TargetObject in project spring-security by spring-projects.
the class MethodInvocationPrivilegeEvaluatorTests method declinesAccessUsingCreate.
@Test
public void declinesAccessUsingCreate() throws Exception {
Object object = new TargetObject();
final MethodInvocation mi = MethodInvocationUtils.create(object, "makeLowerCase", "foobar");
MethodInvocationPrivilegeEvaluator mipe = new MethodInvocationPrivilegeEvaluator();
mipe.setSecurityInterceptor(interceptor);
when(mds.getAttributes(mi)).thenReturn(role);
doThrow(new AccessDeniedException("rejected")).when(adm).decide(token, mi, role);
assertThat(mipe.isAllowed(mi, token)).isFalse();
}
Aggregations