Search in sources :

Example 11 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project stdlib by petergeneric.

the class AuthConstraintInterceptorModule method configure.

@Override
protected void configure() {
    // Use interceptor that checks CurrentUser and calls AccessRefuser to deny access
    final MethodInterceptor interceptor = new AuthConstraintMethodInterceptor(getProvider(CurrentUser.class), config, calls, granted, denied, authenticatedDenied);
    // Collect all REST service interfaces we implement
    Set<Class<?>> restIfaces = RestResourceRegistry.getResources().stream().map(RestResource::getResourceClass).collect(Collectors.toSet());
    Matcher<Method> matcher = new WebMethodMatcher(restIfaces);
    bindInterceptor(Matchers.any(), matcher, interceptor);
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) CurrentUser(com.peterphi.std.guice.common.auth.iface.CurrentUser) Method(java.lang.reflect.Method)

Example 12 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project camunda-bpm-platform by camunda.

the class ProcessScope method createDirtyCheckingProxy.

private Object createDirtyCheckingProxy(final String name, final Object scopedObject) throws Throwable {
    ProxyFactory proxyFactoryBean = new ProxyFactory(scopedObject);
    proxyFactoryBean.setProxyTargetClass(this.proxyTargetClass);
    proxyFactoryBean.addAdvice(new MethodInterceptor() {

        public Object invoke(MethodInvocation methodInvocation) throws Throwable {
            Object result = methodInvocation.proceed();
            persistVariable(name, scopedObject);
            return result;
        }
    });
    return proxyFactoryBean.getProxy(this.classLoader);
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) MethodInvocation(org.aopalliance.intercept.MethodInvocation) ScopedObject(org.springframework.aop.scope.ScopedObject)

Example 13 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-cloud-stream by spring-cloud.

the class DefaultPollableMessageSource method setSource.

public void setSource(MessageSource<?> source) {
    ProxyFactory pf = new ProxyFactory(source);
    class ReceiveAdvice implements MethodInterceptor {

        private final List<ChannelInterceptor> interceptors = new ArrayList<>();

        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            Object result = invocation.proceed();
            if (result instanceof Message) {
                Message<?> received = (Message<?>) result;
                for (ChannelInterceptor interceptor : this.interceptors) {
                    received = interceptor.preSend(received, null);
                    if (received == null) {
                        return null;
                    }
                }
                return received;
            }
            return result;
        }
    }
    final ReceiveAdvice advice = new ReceiveAdvice();
    advice.interceptors.addAll(this.interceptors);
    NameMatchMethodPointcutAdvisor sourceAdvisor = new NameMatchMethodPointcutAdvisor(advice);
    sourceAdvisor.addMethodName("receive");
    pf.addAdvisor(sourceAdvisor);
    this.source = (MessageSource<?>) pf.getProxy();
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Message(org.springframework.messaging.Message) ProxyFactory(org.springframework.aop.framework.ProxyFactory) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) NameMatchMethodPointcutAdvisor(org.springframework.aop.support.NameMatchMethodPointcutAdvisor) ArrayList(java.util.ArrayList) List(java.util.List) MethodInvocation(org.aopalliance.intercept.MethodInvocation)

Example 14 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class SpelEvaluatingMethodInterceptorUnitTests method invokesMethodOnTarget.

// DATAREST-221, DATACMNS-630
@Test
public void invokesMethodOnTarget() throws Throwable {
    when(invocation.getMethod()).thenReturn(Projection.class.getMethod("propertyFromTarget"));
    MethodInterceptor interceptor = new SpelEvaluatingMethodInterceptor(delegate, new Target(), null, parser, Projection.class);
    assertThat(interceptor.invoke(invocation)).isEqualTo("property");
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Test(org.junit.Test)

Example 15 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class SpelEvaluatingMethodInterceptorUnitTests method forwardsParameterIntoSpElExpressionEvaluation.

// DATACMNS-1150
@Test
public void forwardsParameterIntoSpElExpressionEvaluation() throws Throwable {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerSingleton("someBean", new SomeBean());
    when(invocation.getMethod()).thenReturn(Projection.class.getMethod("invokeBeanWithParameter", Integer.class));
    when(invocation.getArguments()).thenReturn(new Object[] { 1 });
    MethodInterceptor interceptor = new SpelEvaluatingMethodInterceptor(delegate, new Target(), factory, parser, Projection.class);
    assertThat(interceptor.invoke(invocation)).isEqualTo("property1");
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Aggregations

MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)57 Test (org.junit.Test)30 MethodInvocation (org.aopalliance.intercept.MethodInvocation)28 List (java.util.List)20 Method (java.lang.reflect.Method)19 ArrayList (java.util.ArrayList)18 Test (org.junit.jupiter.api.Test)15 Advice (org.aopalliance.aop.Advice)14 Map (java.util.Map)13 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)13 AopUtils (org.springframework.aop.support.AopUtils)12 TestBean (org.springframework.beans.testfixture.beans.TestBean)12 ProxyFactory (org.springframework.aop.framework.ProxyFactory)11 HashMap (java.util.HashMap)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)9 Advisor (org.springframework.aop.Advisor)9 Message (org.springframework.messaging.Message)8