Search in sources :

Example 1 with Around

use of org.aspectj.lang.annotation.Around 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 Around

use of org.aspectj.lang.annotation.Around 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 Around

use of org.aspectj.lang.annotation.Around in project PhotoNoter by yydcdut.

the class PermissionAspect method aroundCheckAndRequestPermission.

@Around("pointcut2CheckAndRequestPermissions(aspectPermission)")
public void aroundCheckAndRequestPermission(ProceedingJoinPoint proceedingJoinPoint, AspectPermission aspectPermission) {
    if (aspectPermission == null) {
        return;
    }
    IPresenter iPresenter = (IPresenter) proceedingJoinPoint.getTarget();
    int value = aspectPermission.value();
    switch(value) {
        case PermissionUtils.CODE_CAMERA:
        case PermissionUtils.CODE_ADJUST_CAMERA:
            {
                if (hasPermission4Camera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_STORAGE:
            {
                if (hasPermission4Storage(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_LOCATION_AND_CAMERA:
            {
                if (hasPermission4LocationAndCamera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_AUDIO:
            {
                if (hasPermission4Audio(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_PHONE_STATE:
            {
                if (hasPermission4PhoneState(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
    }
}
Also used : IPresenter(com.yydcdut.note.presenters.IPresenter) Activity(android.app.Activity) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 4 with Around

use of org.aspectj.lang.annotation.Around in project apollo by ctripcorp.

the class RepositoryAspect method invokeWithCatTransaction.

@Around("anyRepositoryMethod()")
public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
    String name = joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName();
    Transaction catTransaction = Tracer.newTransaction("SQL", name);
    try {
        Object result = joinPoint.proceed();
        catTransaction.setStatus(Transaction.SUCCESS);
        return result;
    } catch (Throwable ex) {
        catTransaction.setStatus(ex);
        throw ex;
    } finally {
        catTransaction.complete();
    }
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction) Around(org.aspectj.lang.annotation.Around)

Example 5 with Around

use of org.aspectj.lang.annotation.Around in project books by aidanwhiteley.

the class LimitDataVisibilityAspect method limitBookDataImpl.

@Around("limitBookData()")
public Object limitBookDataImpl(ProceedingJoinPoint joinPoint) throws Throwable {
    Object retVal = joinPoint.proceed();
    Principal principal = getPrincipal(joinPoint);
    // Note - we only look at data from the JWT to build the User here - we
    // are
    // only interested in the users roles and they are in the JWT.
    Optional<User> user = authUtils.extractUserFromPrincipal(principal, true);
    if (retVal instanceof Book) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("About to call setPermissionsAndContentForUser for {}", joinPoint.getSignature());
        }
        ((Book) retVal).setPermissionsAndContentForUser(user.orElse(null));
    } else {
        LOGGER.error("Unexpected return type found by aspect");
    }
    return retVal;
}
Also used : User(com.aidanwhiteley.books.domain.User) Book(com.aidanwhiteley.books.domain.Book) Principal(java.security.Principal) Around(org.aspectj.lang.annotation.Around)

Aggregations

Around (org.aspectj.lang.annotation.Around)192 MethodSignature (org.aspectj.lang.reflect.MethodSignature)49 Method (java.lang.reflect.Method)41 Action (org.apache.nifi.action.Action)40 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)40 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)26 Date (java.util.Date)23 ArrayList (java.util.ArrayList)19 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)19 SimpleDateFormat (java.text.SimpleDateFormat)12 Operation (org.apache.nifi.action.Operation)11 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)11 ProcessGroup (org.apache.nifi.groups.ProcessGroup)9 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)7 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)7 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)6 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)6 ProcessGroupDAO (org.apache.nifi.web.dao.ProcessGroupDAO)6