List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:com.invariantproperties.sandbox.student.webservice.server.rest.CheckPostValues.java
License:Apache License
/** * Check post values on create method.//from ww w. j av a 2 s . c o m * * @param pjp * @return * @throws Throwable */ @Around("target(com.invariantproperties.sandbox.student.webservice.server.rest.AbstractResource) && args(rto,..)") public Object checkParametersCreate(ProceedingJoinPoint pjp, Validatable rto) throws Throwable { final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType()); final String name = pjp.getSignature().getName(); Object results = null; if (rto.validate()) { // this should be safe since parameters have been validated. if (log.isDebugEnabled()) { log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs()))); } results = pjp.proceed(pjp.getArgs()); } else { // FIXME: this is unsafe if (log.isInfoEnabled()) { log.info(String.format("%s(%s): bad arguments", name, Arrays.toString(pjp.getArgs()))); } // TODO: tell caller what the problems were results = Response.status(Status.BAD_REQUEST).build(); } return results; }
From source file:com.invariantproperties.sandbox.student.webservice.server.rest.CheckPostValues.java
License:Apache License
/** * Check post values on update method.// w ww .j a v a2s .c o m * * @param pjp * @return * @throws Throwable */ @Around("target(com.invariantproperties.sandbox.student.webservice.server.rest.AbstractResource) && args(uuid,rto,..)") public Object checkParametersUpdate(ProceedingJoinPoint pjp, String uuid, Validatable rto) throws Throwable { final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType()); final String name = pjp.getSignature().getName(); Object results = null; if (!StudentUtil.isPossibleUuid(uuid)) { // this is a possible attack. if (log.isInfoEnabled()) { log.info(String.format("%s(): uuid", name)); } results = Response.status(Status.BAD_REQUEST).build(); } else if (rto.validate()) { // this should be safe since parameters have been validated. if (log.isDebugEnabled()) { log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs()))); } results = pjp.proceed(pjp.getArgs()); } else { // FIXME: this is unsafe if (log.isInfoEnabled()) { log.info(String.format("%s(%s): bad arguments", name, Arrays.toString(pjp.getArgs()))); } // TODO: tell caller what the problems were results = Response.status(Status.BAD_REQUEST).build(); } return results; }
From source file:com.invariantproperties.sandbox.student.webservice.server.rest.CheckPostValues.java
License:Apache License
/** * Check post values on delete method. This is actually a no-op but it * allows us to log method entry.//w w w .ja v a 2 s .com * * @param pjp * @return * @throws Throwable */ @Around("target(com.invariantproperties.sandbox.student.webservice.server.rest.AbstractResource) && args(uuid,version) && execution(* *.delete*(..))") public Object checkParametersDelete(ProceedingJoinPoint pjp, String uuid, Integer version) throws Throwable { final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType()); final String name = pjp.getSignature().getName(); Object results = null; if (!StudentUtil.isPossibleUuid(uuid)) { // this is a possible attack. if (log.isInfoEnabled()) { log.info(String.format("%s(): uuid", name)); } results = Response.status(Status.BAD_REQUEST).build(); } else { // this should be safe since parameters have been validated. if (log.isDebugEnabled()) { log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs()))); } results = pjp.proceed(pjp.getArgs()); } return results; }
From source file:com.invariantproperties.sandbox.student.webservice.server.rest.CheckPostValues.java
License:Apache License
/** * Check post values on find methods. This is actually a no-op but it allows * us to log method entry.//from w ww . ja v a2 s. c o m * * @param pjp * @return * @throws Throwable */ @Around("target(com.invariantproperties.sandbox.student.webservice.server.rest.AbstractResource) && execution(* *.find*(..))") public Object checkParametersFind(ProceedingJoinPoint pjp) throws Throwable { final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType()); if (log.isDebugEnabled()) { log.debug(String.format("%s(%s): entry", pjp.getSignature().getName(), Arrays.toString(pjp.getArgs()))); } final Object results = pjp.proceed(pjp.getArgs()); return results; }
From source file:com.invariantproperties.sandbox.student.webservice.server.rest.UnexpectedResourceExceptionHandler.java
License:Apache License
/** * Check for an unhandled exception from a REST resource. If we catch one * AND the method returns a Response we can return a Server Internal Error * (500) error code instead of blowing up. We need to check though since * some methods don't return a Response. * // w w w.j a v a2 s.c om * @param pjp * @return * @throws Throwable */ @Around("target(com.invariantproperties.sandbox.student.webservice.server.rest.AbstractResource)") public Object checkForUnhandledException(ProceedingJoinPoint pjp) throws Throwable { Object results = null; Logger log = Logger.getLogger(pjp.getSignature().getClass()); try { results = pjp.proceed(pjp.getArgs()); } catch (ObjectNotFoundException e) { // this is safe to log since we know that we've passed filtering. String args = Arrays.toString(pjp.getArgs()); results = Response.status(Status.NOT_FOUND).entity("object not found: " + args).build(); if (log.isDebugEnabled()) { log.debug("object not found: " + args); } } catch (Exception e) { // find the method we called. We can't cache this since the method // may be overloaded Method method = findMethod(pjp); if ((method != null) && Response.class.isAssignableFrom(method.getReturnType())) { // if the method returns a response we can return a 500 message. if (!(e instanceof UnitTestException)) { if (log.isInfoEnabled()) { log.info(String.format("%s(): unhandled exception: %s", pjp.getSignature().getName(), e.getMessage()), e); } } else if (log.isTraceEnabled()) { log.info("unit test exception: " + e.getMessage()); } results = Response.status(Status.INTERNAL_SERVER_ERROR).build(); } else { // DO NOT LOG THE EXCEPTION. That just clutters the log - let // the final handler log it. throw e; } } return results; }
From source file:com.isotrol.impe3.pms.core.impl.AuthorizationAspect.java
License:Open Source License
private UUID getPortalId(ProceedingJoinPoint pjp) throws AuthorizationException { final Object[] args = pjp.getArgs(); if (args == null || args.length == 0) { log(pjp, "Unable to fetch portal id. Not authorized"); throw new AuthorizationException(); }//w w w .j av a2 s . c o m final Object arg = args[0]; String id = null; if (arg instanceof String) { id = (String) arg; } else if (arg instanceof PortalPagesLoc) { id = ((PortalPagesLoc) arg).getPortalId(); } else if (arg instanceof AbstractWithId) { id = ((AbstractWithId) arg).getId(); } if (id == null) { log(pjp, "Unable to fetch portal id. Not authorized"); throw new AuthorizationException(); } try { return UUID.fromString(id); } catch (IllegalArgumentException e) { log(pjp, "Invalid portal id. Not authorized"); throw new AuthorizationException(); } }
From source file:com.jim.im.config.GenericAopConfig.java
License:Open Source License
@Around("updatePointCut()") protected Object doAroundUpdate(ProceedingJoinPoint pjp) throws Throwable { Object arg = pjp.getArgs()[0]; if (arg instanceof GenericEntity) { entityInterceptor.beforeUpdate((GenericEntity) arg); }//w w w . jav a 2 s . c om Object o = pjp.proceed(); return o; }
From source file:com.jim.im.config.GenericAopConfig.java
License:Open Source License
@Around("addPointCut()") protected Object doAroundAdd(ProceedingJoinPoint pjp) throws Throwable { Object arg = pjp.getArgs()[0]; if (arg instanceof GenericEntity) { entityInterceptor.beforeAdd((GenericEntity) arg); }/*from w w w .j a va2 s .c o m*/ Object o = pjp.proceed(); return o; }
From source file:com.jim.im.config.GenericAopConfig.java
License:Open Source License
@Around("addBatchPointCut()") protected Object doAroundAddBatch(ProceedingJoinPoint pjp) throws Throwable { Object arr = pjp.getArgs()[0]; if (arr.getClass().isArray()) { for (Object obj : (Object[]) arr) { if (obj instanceof GenericEntity) { entityInterceptor.beforeAdd((GenericEntity) obj); }//from w w w.ja v a2s. co m } } Object o = pjp.proceed(); return o; }
From source file:com.jiwhiz.aop.logging.LoggingAspect.java
License:Apache License
@Around("loggingPoincut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { if (log.isDebugEnabled()) { log.debug("==> Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs())); }// ww w. ja v a2 s . c om try { Object result = joinPoint.proceed(); if (log.isDebugEnabled()) { log.debug("<== Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), result); } return result; } catch (IllegalArgumentException e) { log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); throw e; } }