Search in sources :

Example 1 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project head by mifos.

the class AspectJRESTApprovalInterceptor method profile.

@Around("restMethods() && requestMapping() && excludeAPI() && exludeRestfulServices()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    Signature signature = pjp.getStaticPart().getSignature();
    LOG.debug(this.getClass().getSimpleName() + " staring");
    // FIXME : somehow autowiring is not working
    if (approvalService == null) {
        approvalService = ApplicationContextProvider.getBean(ApprovalService.class);
    }
    if (configurationServiceFacade == null) {
        configurationServiceFacade = ApplicationContextProvider.getBean(ConfigurationServiceFacade.class);
    }
    if (parameterNameDiscoverer == null) {
        parameterNameDiscoverer = ApplicationContextProvider.getBean(ParameterNameDiscoverer.class);
    }
    if (!RESTConfigKey.isApprovalRequired(configurationServiceFacade)) {
        LOG.debug(pjp.getSignature() + " skip approval");
        return pjp.proceed();
    }
    if (signature instanceof MethodSignature) {
        MethodSignature ms = (MethodSignature) signature;
        Method m = ms.getMethod();
        RequestMapping mapping = m.getAnnotation(RequestMapping.class);
        if (isReadOnly(mapping)) {
            LOG.debug(m.getName() + " is read only, hence returning control");
            return pjp.proceed();
        }
        Class<?> methodClassType = m.getDeclaringClass();
        if (!methodClassType.getSimpleName().endsWith("RESTController")) {
            LOG.debug(m.getName() + " is not from REST controller, hence returning control");
            return pjp.proceed();
        }
        Object[] argValues = pjp.getArgs();
        Class<?>[] argTypes = m.getParameterTypes();
        String methodName = m.getName();
        String[] names = parameterNameDiscoverer.getParameterNames(m);
        MethodArgHolder args = new MethodArgHolder(argTypes, argValues, names);
        ApprovalMethod method = new ApprovalMethod(methodName, methodClassType, args);
        approvalService.create(method);
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer) ApprovalService(org.mifos.rest.approval.service.ApprovalService) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Method(java.lang.reflect.Method) ConfigurationServiceFacade(org.mifos.config.servicefacade.ConfigurationServiceFacade) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Around(org.aspectj.lang.annotation.Around)

Example 2 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project AndroidDevMetrics by frogermcs.

the class ActivityLifecycleAnalyzer method logAndExecute.

@Around("onCreateMethod() || onStartMethod() || onResumeMethod()")
public Object logAndExecute(ProceedingJoinPoint joinPoint) throws Throwable {
    if (!enabled)
        return joinPoint.proceed();
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    String methodName = signature.getMethod().getName();
    final Object result;
    if (METHOD_ON_RESUME.equals(methodName)) {
        ActivityLifecycleMetrics.getInstance().logPreOnResume((Activity) joinPoint.getTarget());
        result = executeWithTracingIfEnabled(joinPoint, methodName);
        ActivityLifecycleMetrics.getInstance().logPostOnResume((Activity) joinPoint.getTarget());
    } else if (METHOD_ON_START.equals(methodName)) {
        ActivityLifecycleMetrics.getInstance().logPreOnStart((Activity) joinPoint.getTarget());
        result = executeWithTracingIfEnabled(joinPoint, methodName);
        ActivityLifecycleMetrics.getInstance().logPostOnStart((Activity) joinPoint.getTarget());
    } else if (METHOD_ON_CREATE.equals(methodName)) {
        ActivityLifecycleMetrics.getInstance().logPreOnCreate((Activity) joinPoint.getTarget());
        result = executeWithTracingIfEnabled(joinPoint, methodName);
        ActivityLifecycleMetrics.getInstance().logPostOnCreate((Activity) joinPoint.getTarget());
    } else {
        result = null;
    }
    return result;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity) Around(org.aspectj.lang.annotation.Around)

Example 3 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project dq-easy-cloud by dq-open-cloud.

the class DqLogBO method buildDqLogData.

/**
 * <p>
 * 构建日志数据
 * </p>
 *
 * @param pjp
 * @return
 * @author daiqi
 * 创建时间    2018年2月9日 上午11:14:51
 */
public DqLogBO buildDqLogData(ProceedingJoinPoint pjp) {
    Signature signature = pjp.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;
    Method targetMethod = methodSignature.getMethod();
    Class<?> targetClass = pjp.getTarget().getClass();
    this.buildTargetClassName(targetClass.getName()).buildTargetMethodName(targetMethod.getName());
    this.buildTargetParameterTypes(targetMethod.getParameterTypes()).buildTargetParameterValues(pjp.getArgs());
    this.buildTargetReturnType(targetMethod.getReturnType()).buildLogger(targetClass);
    this.buildRequestPath().buildDqLog(targetClass, targetMethod);
    return this;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 4 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project entando-core by entando.

the class CacheInfoManager method aroundCacheInfoEvictMethod.

@Around("@annotation(cacheInfoEvict)")
public Object aroundCacheInfoEvictMethod(ProceedingJoinPoint pjp, CacheInfoEvict cacheInfoEvict) throws Throwable {
    try {
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method targetMethod = methodSignature.getMethod();
        Class targetClass = pjp.getTarget().getClass();
        Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
        String[] cacheNames = cacheInfoEvict.value();
        Object groupsCsv = this.evaluateExpression(cacheInfoEvict.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
        if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
            String[] groups = groupsCsv.toString().split(",");
            for (String group : groups) {
                for (String cacheName : cacheNames) {
                    this.flushGroup(cacheName, group);
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error while flushing group", t);
        throw new ApsSystemException("Error while flushing group", t);
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Example 5 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project bamboobsc by billchen198318.

the class HessianServiceProxyAspect method proxyProcess.

private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = AspectConstants.getServiceId(annotations);
    /**
		 * 不需要被遠端代理的 service-bean
		 */
    if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
        //logger.info( "reject proxy service: " + serviceId );
        return pjp.proceed();
    }
    String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());
    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
        /**
			 * 沒使用者資訊不能處理遠端代理的 service-bean
			 */
        if (StringUtils.isBlank(userId)) {
            logger.warn("no userId");
            pjp.proceed();
        }
        /**
			 * 此使用者不能存取遠端代理的 service-bean
			 */
        if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
            logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
            return pjp.proceed();
        }
    }
    String serviceInterfacesName = "";
    Class<?>[] serviceInterfaces = pjp.getTarget().getClass().getInterfaces();
    for (Class<?> clazz : serviceInterfaces) {
        if (clazz.getName().indexOf(".service.") > -1) {
            serviceInterfacesName = clazz.getName();
        }
    }
    if (StringUtils.isBlank(serviceInterfacesName)) {
        logger.error("error no service interface: " + serviceId);
        throw new Exception("error no service interface: " + serviceId);
    }
    String url = GreenStepHessianUtils.getServiceUrl(serviceId);
    String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/" + ApplicationSiteUtils.getContextPath(Constants.getSystem());
    /**
		 * 不要自己呼叫遠端代理的自己, 會造成 HessianServiceProxyAspect 一直重複觸發 (客戶端與server-remote同一台的情況下)
		 * 如客戶端是 http://127.0.0.1:8080/
		 * 但是客戶端有開啟 hessian.enable=Y 呼叫遠端代理, 然後遠端url設定為 hessian.serverUrl=http://127.0.0.1:8080/
		 * 
		 */
    if (url.indexOf(theSystemPath) > -1) {
        logger.error("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
        throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
    }
    logger.info("proxy url = " + url);
    HessianProxyFactory factory = null;
    Object proxyServiceObject = null;
    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
        // 一般要checkValue模式
        factory = new GreenStepHessianProxyFactory();
        ((GreenStepHessianProxyFactory) factory).setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
        proxyServiceObject = ((GreenStepHessianProxyFactory) factory).createForHeaderMode(Class.forName(serviceInterfacesName), url);
    } else {
        // 不使用checkValue模式
        factory = new HessianProxyFactory();
        proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
    }
    Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
    Method proxyObjectMethod = null;
    if (null == proxyObjectMethods) {
        logger.error("error no find proxy method: " + serviceId);
        throw new Exception("error no find proxy method: " + serviceId);
    }
    for (Method m : proxyObjectMethods) {
        if (m.getName().equals(signature.getMethod().getName()) && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
            proxyObjectMethod = m;
        }
    }
    if (null == proxyObjectMethod) {
        logger.error("error no execute proxy method: " + serviceId);
        throw new Exception("error no execute proxy method: " + serviceId);
    }
    Object resultObj = null;
    try {
        resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
        this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
    } catch (InvocationTargetException e) {
        if (e.getMessage() != null) {
            throw new ServiceException(e.getMessage().toString());
        }
        if (e.getTargetException().getMessage() != null) {
            throw new ServiceException(e.getTargetException().getMessage().toString());
        }
        throw e;
    } catch (Exception e) {
        logger.error(e.getMessage().toString());
        throw e;
    }
    logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
    return resultObj;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) GreenStepHessianProxyFactory(com.netsteadfast.greenstep.sys.GreenStepHessianProxyFactory) HessianProxyFactory(com.caucho.hessian.client.HessianProxyFactory) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) AuthorityException(com.netsteadfast.greenstep.base.exception.AuthorityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) GreenStepHessianProxyFactory(com.netsteadfast.greenstep.sys.GreenStepHessianProxyFactory)

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