Search in sources :

Example 36 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project vip by guangdada.

the class PermissionAop method doPermission.

@Around("cutPermission()")
public Object doPermission(ProceedingJoinPoint point) throws Throwable {
    MethodSignature ms = (MethodSignature) point.getSignature();
    Method method = ms.getMethod();
    Permission permission = method.getAnnotation(Permission.class);
    Object[] permissions = permission.value();
    if (permissions == null || permissions.length == 0) {
        // 检查全体角色
        boolean result = PermissionCheckManager.checkAll();
        if (result) {
            return point.proceed();
        } else {
            throw new NoPermissionException();
        }
    } else {
        // 检查指定角色
        boolean result = PermissionCheckManager.check(permissions);
        if (result) {
            return point.proceed();
        } else {
            throw new NoPermissionException();
        }
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Permission(com.ikoori.vip.common.annotion.Permission) NoPermissionException(javax.naming.NoPermissionException) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Example 37 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project resilience4j by resilience4j.

the class RateLimiterAspect method rateLimiterAroundAdvice.

@Around(value = "matchAnnotatedClassOrMethod(limitedService)", argNames = "proceedingJoinPoint, limitedService")
public Object rateLimiterAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, RateLimiter limitedService) throws Throwable {
    RateLimiter targetService = limitedService;
    Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
    String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
    if (targetService == null) {
        targetService = getRateLimiterAnnotation(proceedingJoinPoint);
    }
    String name = targetService.name();
    io.github.resilience4j.ratelimiter.RateLimiter rateLimiter = getOrCreateRateLimiter(methodName, name);
    return handleJoinPoint(proceedingJoinPoint, rateLimiter, methodName);
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) RateLimiter(io.github.resilience4j.ratelimiter.annotation.RateLimiter) Around(org.aspectj.lang.annotation.Around)

Example 38 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project resilience4j by resilience4j.

the class CircuitBreakerAspect method circuitBreakerAroundAdvice.

@Around(value = "matchAnnotatedClassOrMethod(backendMonitored)", argNames = "proceedingJoinPoint, backendMonitored")
public Object circuitBreakerAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, CircuitBreaker backendMonitored) throws Throwable {
    Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
    String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
    if (backendMonitored == null) {
        backendMonitored = getBackendMonitoredAnnotation(proceedingJoinPoint);
    }
    String backend = backendMonitored.backend();
    io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = getOrCreateCircuitBreaker(methodName, backend);
    return handleJoinPoint(proceedingJoinPoint, circuitBreaker, methodName);
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Example 39 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project jim-framework by jiangmin168168.

the class AbstractRequestLockInterceptor method doAround.

@Around("pointcut()")
public Object doAround(ProceedingJoinPoint point) throws Throwable {
    Signature signature = point.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;
    Method method = methodSignature.getMethod();
    String targetName = point.getTarget().getClass().getName();
    String methodName = point.getSignature().getName();
    Object[] arguments = point.getArgs();
    if (method != null && method.isAnnotationPresent(RequestLockable.class)) {
        logger.info("RequestLockable doAround start");
        RequestLockable requestLockable = method.getAnnotation(RequestLockable.class);
        String requestLockKey = getLockKey(method, targetName, methodName, requestLockable.key(), arguments);
        Lock lock = this.getLock(requestLockKey);
        boolean isLock = this.tryLock(requestLockable.maximumWaiteTime(), requestLockable.expirationTime(), requestLockable.timeUnit(), lock);
        if (isLock) {
            try {
                logger.info("RequestLockable point.proceed start");
                return point.proceed();
            } finally {
                try {
                    lock.unlock();
                } catch (IllegalMonitorStateException e) {
                    logger.info("not locked by current thread", e);
                }
            }
        } else {
            logger.error("get lock error,key:{}", requestLockKey);
            // 多线程场景下主线程捕获异常需要注意,不同的调用方式可能会影响异常的抛出
            throw new RuntimeException("get lock error");
        }
    }
    return point.proceed();
}
Also used : RequestLockable(com.jim.framework.annotationlock.annotation.RequestLockable) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) Lock(java.util.concurrent.locks.Lock) Around(org.aspectj.lang.annotation.Around)

Example 40 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project micrometer by micrometer-metrics.

the class TimedAspect method timedMethod.

@Around("execution (@io.micrometer.core.annotation.Timed * *.*(..))")
public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
    Method method = ((MethodSignature) pjp.getSignature()).getMethod();
    Timed timed = method.getAnnotation(Timed.class);
    final String metricName = timed.value().isEmpty() ? DEFAULT_METRIC_NAME : timed.value();
    Timer.Sample sample = Timer.start(registry);
    try {
        return pjp.proceed();
    } finally {
        sample.stop(Timer.builder(metricName).description(timed.description().isEmpty() ? null : timed.description()).tags(timed.extraTags()).tags(tagsBasedOnJoinpoint.apply(pjp)).publishPercentileHistogram(timed.histogram()).publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles()).register(registry));
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Timer(io.micrometer.core.instrument.Timer) Timed(io.micrometer.core.annotation.Timed) 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