use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class HttpInvokerTests method httpInvokerProxyFactoryBeanAndServiceExporterWithCustomInvocationObject.
@Test
public void httpInvokerProxyFactoryBeanAndServiceExporterWithCustomInvocationObject() throws Exception {
TestBean target = new TestBean("myname", 99);
final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setServiceInterface(ITestBean.class);
exporter.setService(target);
exporter.setRemoteInvocationExecutor(new DefaultRemoteInvocationExecutor() {
@Override
public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
assertTrue(invocation instanceof TestRemoteInvocation);
assertNull(invocation.getAttributes());
assertNull(invocation.getAttribute("myKey"));
return super.invoke(invocation, targetObject);
}
});
exporter.afterPropertiesSet();
HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceInterface(ITestBean.class);
pfb.setServiceUrl("http://myurl");
pfb.setRemoteInvocationFactory(new RemoteInvocationFactory() {
@Override
public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
RemoteInvocation invocation = new TestRemoteInvocation(methodInvocation);
assertNull(invocation.getAttributes());
assertNull(invocation.getAttribute("myKey"));
return invocation;
}
});
pfb.setHttpInvokerRequestExecutor(new AbstractHttpInvokerRequestExecutor() {
@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception {
assertEquals("http://myurl", config.getServiceUrl());
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setContent(baos.toByteArray());
exporter.handleRequest(request, response);
return readRemoteInvocationResult(new ByteArrayInputStream(response.getContentAsByteArray()), config.getCodebaseUrl());
}
});
pfb.afterPropertiesSet();
ITestBean proxy = (ITestBean) pfb.getObject();
assertEquals("myname", proxy.getName());
assertEquals(99, proxy.getAge());
}
use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class RmiSupportTests method remoteInvocation.
@Test
public void remoteInvocation() throws NoSuchMethodException {
// let's see if the remote invocation object works
final RemoteBean rb = new RemoteBean();
final Method setNameMethod = rb.getClass().getDeclaredMethod("setName", String.class);
MethodInvocation mi = new MethodInvocation() {
@Override
public Method getMethod() {
return setNameMethod;
}
@Override
public Object[] getArguments() {
return new Object[] { "bla" };
}
@Override
public Object proceed() throws Throwable {
throw new UnsupportedOperationException();
}
@Override
public Object getThis() {
return rb;
}
@Override
public AccessibleObject getStaticPart() {
return setNameMethod;
}
};
RemoteInvocation inv = new RemoteInvocation(mi);
assertEquals("setName", inv.getMethodName());
assertEquals("bla", inv.getArguments()[0]);
assertEquals(String.class, inv.getParameterTypes()[0]);
// this is a bit BS, but we need to test it
inv = new RemoteInvocation();
inv.setArguments(new Object[] { "bla" });
assertEquals("bla", inv.getArguments()[0]);
inv.setMethodName("setName");
assertEquals("setName", inv.getMethodName());
inv.setParameterTypes(new Class<?>[] { String.class });
assertEquals(String.class, inv.getParameterTypes()[0]);
inv = new RemoteInvocation("setName", new Class<?>[] { String.class }, new Object[] { "bla" });
assertEquals("bla", inv.getArguments()[0]);
assertEquals("setName", inv.getMethodName());
assertEquals(String.class, inv.getParameterTypes()[0]);
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class TestVoter method vote.
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> config) {
MethodInvocation mi = (MethodInvocation) object;
mi.getMethod().getParameterAnnotations();
return ACCESS_GRANTED;
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testScopes.
@Test
public void testScopes() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testOauthClient"));
EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.hasAnyScope('read','write')");
assertTrue((Boolean) expression.getValue(context));
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testNonOauthClient.
@Test
public void testNonOauthClient() throws Exception {
Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar");
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testNonOauthClient"));
EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.clientHasAnyRole()");
assertFalse((Boolean) expression.getValue(context));
}
Aggregations