Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:org.opensaas.jaudit.service.spring.TransactionEventBridge.java

License:LGPL

/**
 * Create an audit record detailing that a particular operation has taken
 * place./*from ww w.java  2s  .  co m*/
 * 
 * @param jp
 *            The join point currently being fired.
 * @param annotation
 *            The required annotation that triggers this join point.
 * @return The result of executing the method wrapped by this join point.
 * @throws Throwable
 *             When there is an error.
 */
public Object recordAction(final ProceedingJoinPoint jp) throws Throwable {

    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "joinpoint={0}, target={2}, args={1}", new Object[] {
                jp.getSignature().toLongString(), Arrays.toString(jp.getArgs()), jp.getTarget() });
    }

    // make the call
    final Object retval = jp.proceed();

    if (PlatformTransactionManager.class.isAssignableFrom(jp.getTarget().getClass())) {

        final SessionRecord sr = AuditSession.getAuditSession() != null
                ? AuditSession.getAuditSession().getSessionRecord()
                : null;

        final String methodName = jp.getSignature().getName();

        if ("getTransaction".equals(methodName)) {
            final TransactionStatus ts = (TransactionStatus) retval;

            if (ts.isNewTransaction()) {
                _applicationContext.publishEvent(
                        new NewTransactionEvent((PlatformTransactionManager) jp.getTarget(), ts, sr));
            }
        }
    }

    return retval;
}

From source file:org.opentestsystem.delivery.testreg.aop.SecuredAnnotationAspect.java

License:Open Source License

@Around("execution(* org.opentestsystem.delivery.test*.*.*Controller.*(..)) && @annotation(method) && @annotation(secured)")
public Object aroundMethodInControllerClass(ProceedingJoinPoint pjp, final RequestMapping method,
        final Secured secured) throws Throwable {

    String[] permissions = secured.value();
    Object[] params = pjp.getArgs();
    Object retVal = null;//from   w w  w .j a  v  a 2s. com

    if (method.method() != null) {
        for (RequestMethod requestMethod : method.method()) {
            LOGGER.debug("intercepting " + requestMethod + " for " + pjp.toString() + " secured by "
                    + permissionArrayToString(permissions));
            if (requestMethod.equals(POST) || requestMethod.equals(PUT) || requestMethod.equals(DELETE)
                    || requestMethod.equals(PATCH)) {
                // in these situations we need to check the incoming params to deduce if we have access prior to the
                // action
                if (params != null) {
                    if (!checkIncomingParameters(params, permissions)) {
                        throw new AccessDeniedException("permission denied");
                    }
                    // in this special case we want to check if the file upload type specified in the params matches
                    // what file upload permission(s) the user has...
                    // they are allowed to upload based on having any one of these: "ROLE_Accommodations Upload",
                    // "ROLE_Student Upload", "ROLE_Entity Upload", "ROLE_StudentGroup Upload", "ROLE_User Upload, "ROLE_ExplicitEligibility Upload"
                    if (pjp.getSignature().getName().equals("uploadFile")
                            && pjp.getSignature().getDeclaringType().equals(Class.forName(
                                    "org.opentestsystem.delivery.testreg.rest.FileUploadDataController"))) {
                        // We should throw AccessDeniedException here if they don't have the proper upload
                        // role based on the file upload type (check params)
                        SbacUser currentUser = testRegUserDetailsService.getCurrentUser();
                        String testRegPermission = getCorrectRolePermissionByFormatType((String) params[1]);
                        // checking if logged-in-user has permission to upload corresponding file(user/student/institutions/..)
                        if (currentUser != null && !currentUser.hasPermission(testRegPermission)) {
                            throw new AccessDeniedException("permission denied");
                        }
                    } else if (pjp.getSignature().getName().equals("saveStudents")
                            && pjp.getSignature().getDeclaringType().equals(Class.forName(
                                    "org.opentestsystem.delivery.testreg.rest.ExternalStudentController"))) {
                        // We should throw AccessDeniedException here if they don't have the proper upload
                        // role based on the file upload type (check params)
                        SbacUser currentUser = testRegUserDetailsService.getCurrentUser();
                        String testRegPermission = getCorrectRolePermissionByFormatType("STUDENT");
                        // checking if logged-in-user has permission to upload corresponding file(user/student/institutions/..)
                        if (currentUser != null && !currentUser.hasPermission(testRegPermission)) {
                            throw new AccessDeniedException("permission denied");
                        }
                    }
                }
                // we let things continue normally...
                retVal = pjp.proceed();
            } else if (requestMethod.equals(GET)) {
                // in these situations we need to check the return values to determine if we have access
                retVal = pjp.proceed();
                if (retVal != null && !checkReturnValue(retVal, permissions)) {
                    throw new AccessDeniedException("permission denied");
                }
            } else {
                // for now we only handle securing methods get/post/put/delete (enhance code here for additional
                // request methods)
                throw new AccessDeniedException(
                        "non-standard request type for a @Secured rest request: " + requestMethod);
            }
        }
    }
    return retVal;
}

From source file:org.opentestsystem.shared.mna.client.aop.MnaClientLoggingAdvice.java

License:Open Source License

/**
 * {@inheritDoc}//from w w w.j av  a2s . c o  m
 */
@Override
public Object timeMethod(final ProceedingJoinPoint inPjp, final Logger inPerformanceLogger) {
    Object output = null;

    try {

        // only do this if debug is enabled
        if (inPerformanceLogger != null && inPerformanceLogger.isDebugEnabled()) {
            long start = System.currentTimeMillis();
            String jpStr = getJoinPointLogString(inPjp);
            inPerformanceLogger.debug("Begin " + jpStr);
            output = inPjp.proceed();
            long stop = System.currentTimeMillis();
            long elapsedTime = stop - start;
            // log out to the appender that is configured
            inPerformanceLogger.debug("End   " + jpStr + " Elapsed Time: " + elapsedTime + " ms");
            if (mnaMetricClient != null) {
                String sig = inPjp.getSignature().getDeclaringType().getSimpleName();
                // allow string concatenation, this isn't a big deal
                sig = sig + "." + inPjp.getSignature().getName(); // NOPMD

                // send the performance number to Monitoring and Alerting as a metric
                mnaMetricClient.sendPerformanceMetricToMna(sig, elapsedTime);
            }
        } else {
            output = inPjp.proceed();
        }
        // allow catch of throwable because the AOP proceed call throws Throwable, also allow rethrowing as a generic
        // RuntimeException
    } catch (Throwable thr) { // NOPMD
        if (thr instanceof RuntimeException) { // NOPMD
            LOGGER.error("Caught RuntimeException in Around Advice, rethrowing", thr);
            throw (RuntimeException) thr;
        } else {
            LOGGER.error("Caught a non-RuntimeException error in AroundAdvice, rethrowing as RuntimeException",
                    thr);
            throw new RuntimeException(
                    "Caught a non-RuntimeException error in AroundAdvice, rethrowing as RuntimeException", thr); // NOPMD
        }
    }
    return output;
}

From source file:org.oscarehr.ws.rest.util.WebServiceLoggingAdvice.java

License:Open Source License

private String getServiceCallDescription(ProceedingJoinPoint joinpoint) {
    Signature signature = joinpoint.getSignature();
    String type = signature.getDeclaringType().getSimpleName();
    String methodName = signature.getName();
    return type + "." + methodName;
}

From source file:org.perf4j.aop.AbstractTimingAspect.java

License:Open Source License

protected Object runProfiledMethod(final ProceedingJoinPoint pjp, Profiled profiled) throws Throwable {
    //We just delegate to the super class, wrapping the AspectJ-specific ProceedingJoinPoint as an AbstractJoinPoint
    return runProfiledMethod(new AbstractJoinPoint() {
        public Object proceed() throws Throwable {
            return pjp.proceed();
        }//from  ww w .  j a  va2s  . co m

        public Object getExecutingObject() {
            return pjp.getThis();
        }

        public Object[] getParameters() {
            return pjp.getArgs();
        }

        public String getMethodName() {
            return pjp.getSignature().getName();
        }

        public Class<?> getDeclaringClass() {
            return pjp.getSignature().getDeclaringType();
        }

        public Map<String, Object> getContextData() {
            return new HashMap<String, Object>();
        }
    }, profiled, newStopWatch(profiled.logger() + "", profiled.level()));
}

From source file:org.qifu.base.aspect.ServiceAuthorityCheckAspect.java

License:Apache License

@Around(AspectConstants.LOGIC_SERVICE_PACKAGE)
public Object logicServiceProcess(ProceedingJoinPoint pjp)
        throws AuthorityException, ServiceException, Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = AspectConstants.getServiceId(annotations);
    Subject subject = SecurityUtils.getSubject();
    Method method = signature.getMethod();
    if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) {
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }//  w ww. j ava  2 s . c  om
    if (StringUtils.isBlank(serviceId)) { //  service id  
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    if (!this.isServiceAuthorityCheck(annotations)) { //  ServiceAuthority  check=false ? 
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    Annotation[] methodAnnotations = method.getAnnotations();
    if (this.isServiceMethodAuthority(serviceId, methodAnnotations, subject)) {
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    logger.warn("[decline] user[" + subject.getPrincipal() + "] " + pjp.getTarget().getClass().getName() + " - "
            + signature.getMethod().getName());
    SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
            this.getEventId(serviceId, method.getName()), false);
    throw new AuthorityException(SysMessageUtil.get(SysMsgConstants.NO_PERMISSION));
}

From source file:org.rapharino.base.api.result.ResultUtil.java

License:Open Source License

public static Object createErrorResult(ProceedingJoinPoint pjp, String requestIp, int code, String msg) {
    Signature signature = pjp.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;
    Class<?> clazz = methodSignature.getReturnType();
    Object object = null;/*from w ww .  ja va  2s .co m*/
    try {
        object = clazz.newInstance();
    } catch (InstantiationException e) {
        LOGGER.error("createErrorResult-InstantiationException", e);
        throw new ApiException(ResultCode.INTERNAL_ERROR);
    } catch (IllegalAccessException e) {
        LOGGER.error("createErrorResult-IllegalAccessException", e);
        throw new ApiException(ResultCode.INTERNAL_ERROR);
    }
    if (object instanceof BaseResult) {
        ((BaseResult) object).setErrorMessage(code, msg);
        ((BaseResult) object).setRequestIp(requestIp);
    }
    return object;
}

From source file:org.raspinloop.fmi.RILLogingAspect.java

License:Apache License

@Around("org.raspinloop.fmi.RILLogingAspect.rilTraceCall()")
public Object myTrace(ProceedingJoinPoint joinPoint) throws Throwable {

    StringBuilder sb = new StringBuilder("ril:--> " + joinPoint.getTarget().getClass().getName() + "."
            + joinPoint.getSignature().getName() + ": ");
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < annotations.length; ++i) {
        sb.append(joinPoint.getArgs()[i]);
        if (i != annotations.length - 1)
            sb.append(", ");
    }/*from w  w  w  . ja va2 s  . c om*/
    logger.trace(sb.toString());

    Object retVal = null;
    try {
        retVal = joinPoint.proceed();
    } finally {

        logger.trace("ril:<-- " + joinPoint.getTarget().getClass().getName() + "."
                + joinPoint.getSignature().getName() + " retval=" + retVal);
    }
    return retVal;
}

From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java

License:Apache License

@Around("call(* org.springframework.data.mongodb.core.MongoTemplate.*(..)) && !this(MongoTrackingAspect) && !within(org..*Test) && !within(org..*MongoPerfRepository)")
public Object track(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.currentTimeMillis();
    Object result = pjp.proceed();
    long end = System.currentTimeMillis();

    if (isEnabled()) {
        MongoTemplate mt = (MongoTemplate) pjp.getTarget();
        String collection = determineCollectionName(pjp);
        proceedAndTrack(pjp, mt.getDb().getName(), pjp.getSignature().getName(), collection, start, end);
    }/* www  .  ja v  a  2 s .c  o m*/
    if (Boolean.valueOf(dbCallTracking)) {
        dbCallTracker.incrementHitCount();
        // dbCallTracker.addMetric("t", pjp.getSignature().toShortString(), end-start);
    }

    return result;
}