Search in sources :

Example 46 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project skeleton-commons by skeleton-software-community.

the class AccessControlAspect method getTokenExtractionMode.

private TokenExtractionMode getTokenExtractionMode(ProceedingJoinPoint joinPoint) {
    TokenExtractionMode tokenExtractionMode = TokenExtractionMode.HEADER;
    Method proxiedMethod = ((MethodSignature) joinPoint.getSignature()).getMethod();
    AccessControl accessControl = proxiedMethod.getAnnotation(AccessControl.class);
    if (accessControl != null) {
        tokenExtractionMode = accessControl.tokenExtractionMode();
    }
    return tokenExtractionMode;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) TokenExtractionMode(org.sklsft.commons.rest.security.tokens.TokenExtractionMode) Method(java.lang.reflect.Method) AccessControl(org.sklsft.commons.rest.security.annotations.AccessControl)

Example 47 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project hugo by JakeWharton.

the class Hugo method exitMethod.

private static void exitMethod(JoinPoint joinPoint, Object result, long lengthMillis) {
    if (!enabled)
        return;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        Trace.endSection();
    }
    Signature signature = joinPoint.getSignature();
    Class<?> cls = signature.getDeclaringType();
    String methodName = signature.getName();
    boolean hasReturnType = signature instanceof MethodSignature && ((MethodSignature) signature).getReturnType() != void.class;
    StringBuilder builder = new StringBuilder("\u21E0 ").append(methodName).append(" [").append(lengthMillis).append("ms]");
    if (hasReturnType) {
        builder.append(" = ");
        builder.append(Strings.toString(result));
    }
    Log.v(asTag(cls), builder.toString());
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) CodeSignature(org.aspectj.lang.reflect.CodeSignature)

Example 48 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project disconf by knightliao.

the class DisconfAspectJ method decideAccess.

/**
 * 获取配置文件数据, 只有开启disconf远程才会进行切面
 *
 * @throws Throwable
 */
@Around("anyPublicMethod() && @annotation(disconfFileItem)")
public Object decideAccess(ProceedingJoinPoint pjp, DisconfFileItem disconfFileItem) throws Throwable {
    if (DisClientConfig.getInstance().ENABLE_DISCONF) {
        MethodSignature ms = (MethodSignature) pjp.getSignature();
        Method method = ms.getMethod();
        // 
        // 文件名
        // 
        Class<?> cls = method.getDeclaringClass();
        DisconfFile disconfFile = cls.getAnnotation(DisconfFile.class);
        // 
        // Field名
        // 
        Field field = MethodUtils.getFieldFromMethod(method, cls.getDeclaredFields(), DisConfigTypeEnum.FILE);
        if (field != null) {
            // 
            // 请求仓库配置数据
            // 
            DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.getDisconfStoreFileProcessor();
            Object ret = disconfStoreProcessor.getConfig(disconfFile.filename(), disconfFileItem.name());
            if (ret != null) {
                LOGGER.debug("using disconf store value: " + disconfFile.filename() + " (" + disconfFileItem.name() + " , " + ret + ")");
                return ret;
            }
        }
    }
    Object rtnOb;
    try {
        // 返回原值
        rtnOb = pjp.proceed();
    } catch (Throwable t) {
        LOGGER.info(t.getMessage());
        throw t;
    }
    return rtnOb;
}
Also used : Field(java.lang.reflect.Field) MethodSignature(org.aspectj.lang.reflect.MethodSignature) DisconfFile(com.baidu.disconf.client.common.annotations.DisconfFile) Method(java.lang.reflect.Method) DisconfStoreProcessor(com.baidu.disconf.client.store.DisconfStoreProcessor) Around(org.aspectj.lang.annotation.Around)

Example 49 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project spring-framework by spring-projects.

the class MethodInvocationProceedingJoinPointTests method testCanGetMethodSignatureFromJoinPoint.

@Test
public void testCanGetMethodSignatureFromJoinPoint() {
    final Object raw = new TestBean();
    // Will be set by advice during a method call
    final int newAge = 23;
    ProxyFactory pf = new ProxyFactory(raw);
    pf.setExposeProxy(true);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    AtomicInteger depth = new AtomicInteger();
    pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
        JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
        assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue();
        // Ensure that these don't cause problems
        jp.toShortString();
        jp.toLongString();
        assertThat(AbstractAspectJAdvice.currentJoinPoint().getTarget()).isSameAs(target);
        assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())).isFalse();
        ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
        assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())).isTrue();
        assertThat(thisProxy).isNotSameAs(target);
        // Check getting again doesn't cause a problem
        assertThat(AbstractAspectJAdvice.currentJoinPoint().getThis()).isSameAs(thisProxy);
        // Be sure to increment depth to avoid infinite recursion
        if (depth.getAndIncrement() == 0) {
            // Check that toString doesn't cause a problem
            thisProxy.toString();
            // Change age, so this will be returned by invocation
            thisProxy.setAge(newAge);
            assertThat(thisProxy.getAge()).isEqualTo(newAge);
        }
        assertThat(thisProxy).isSameAs(AopContext.currentProxy());
        assertThat(raw).isSameAs(target);
        assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()).isSameAs(method.getName());
        assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()).isEqualTo(method.getModifiers());
        MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
        assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature()).as("Return same MethodSignature repeatedly").isSameAs(msig);
        assertThat(AbstractAspectJAdvice.currentJoinPoint()).as("Return same JoinPoint repeatedly").isSameAs(AbstractAspectJAdvice.currentJoinPoint());
        assertThat(msig.getDeclaringType()).isEqualTo(method.getDeclaringClass());
        assertThat(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())).isTrue();
        assertThat(msig.getReturnType()).isEqualTo(method.getReturnType());
        assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue();
        msig.toLongString();
        msig.toShortString();
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    assertThat(itb.getAge()).as("Advice reentrantly set age").isEqualTo(newAge);
}
Also used : ExposeInvocationInterceptor(org.springframework.aop.interceptor.ExposeInvocationInterceptor) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Arrays(java.util.Arrays) AopUtils(org.springframework.aop.support.AopUtils) SourceLocation(org.aspectj.lang.reflect.SourceLocation) Factory(org.aspectj.runtime.reflect.Factory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) AopContext(org.springframework.aop.framework.AopContext) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test) StaticPart(org.aspectj.lang.JoinPoint.StaticPart) MethodBeforeAdvice(org.springframework.aop.MethodBeforeAdvice) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) TestBean(org.springframework.beans.testfixture.beans.TestBean) MethodSignature(org.aspectj.lang.reflect.MethodSignature) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Example 50 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project java-chassis by ServiceComb.

the class ZipkinSpanAspect method advise.

@Around("execution(@org.apache.servicecomb.tracing.Span * *(..)) && @annotation(spanAnnotation)")
public Object advise(ProceedingJoinPoint joinPoint, Span spanAnnotation) throws Throwable {
    String spanName = spanAnnotation.spanName();
    String callPath = spanAnnotation.callPath();
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    LOG.debug("Generating zipkin span for method {}", method.toString());
    if ("".equals(spanName)) {
        spanName = method.getName();
    }
    if ("".equals(callPath)) {
        callPath = method.toString();
    }
    return adviser.invoke(spanName, callPath, joinPoint::proceed);
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Aggregations

MethodSignature (org.aspectj.lang.reflect.MethodSignature)116 Method (java.lang.reflect.Method)95 Around (org.aspectj.lang.annotation.Around)43 JoinPoint (org.aspectj.lang.JoinPoint)30 AccessDeniedException (org.springframework.security.access.AccessDeniedException)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 Test (org.junit.Test)25 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)24 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)21 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)14 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)13 Signature (org.aspectj.lang.Signature)13 Annotation (java.lang.annotation.Annotation)10 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 List (java.util.List)2 Tick (mysh.util.Tick)2 Ignite (org.apache.ignite.Ignite)2