MethodInvocationAdapter(JoinPoint jp) { this.jp = (ProceedingJoinPoint) jp; if (jp.getTarget() != null) { target = jp.getTarget(); } else { // SEC-1295: target may be null if an ITD is in use target = jp.getSignature().getDeclaringType(); } String targetMethodName = jp.getStaticPart().getSignature().getName(); Class<?>[] types = ((CodeSignature) jp.getStaticPart().getSignature()) .getParameterTypes(); Class<?> declaringType = jp.getStaticPart().getSignature().getDeclaringType(); method = findMethod(targetMethodName, declaringType, types); if (method == null) { throw new IllegalArgumentException( "Could not obtain target method from JoinPoint: '" + jp + "'"); } }
@Override public void before(Method method, Object[] args, @Nullable Object target) throws Throwable { StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart(); assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart()); assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind()); assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature()); assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation()); } });
@Override public void before(Method method, Object[] args, @Nullable Object target) throws Throwable { // makeEncSJP, although meant for computing the enclosing join point, // it serves our purpose here JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method); JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint(); assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString()); assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString()); assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString()); assertEquals(aspectJVersionJp.toLongString(), jp.toLongString()); assertEquals(aspectJVersionJp.toShortString(), jp.toShortString()); assertEquals(aspectJVersionJp.toString(), jp.toString()); } });
} else { JoinPoint jp = (JoinPoint) secureObject; params = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes(); args = jp.getArgs();
Signature sig = joinPointStaticPart.getSignature(); String sign= sig.getDeclaringType().getName()+"."+sig.getName(); return sign;
@SuppressWarnings({ "rawtypes", "unchecked" }) @Around("call(@com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous * *(..)) && @annotation(asynchronousAnnotation)") public Object makeAsynchronous(ProceedingJoinPoint pjp, Asynchronous asynchronousAnnotation) throws Throwable { final Signature signature = pjp.getStaticPart().getSignature(); if (signature instanceof MethodSignature) { final MethodSignature methodSignature = (MethodSignature) signature;
@SuppressWarnings({ "rawtypes", "unchecked" }) @Around("call(@com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous * *(..)) && @annotation(asynchronousAnnotation)") public Object makeAsynchronous(ProceedingJoinPoint pjp, Asynchronous asynchronousAnnotation) throws Throwable { final Signature signature = pjp.getStaticPart().getSignature(); if (signature instanceof MethodSignature) { final MethodSignature methodSignature = (MethodSignature) signature;
/** * This is an advice which will be used after the construction of an object. * * @param thisObject * @param jp * The static information about this joint point. */ // HINT: This may be logged multiple times due to super constructor calls... @AfterReturning("monitoredConstructor() && this(thisObject) && notWithinKieker()") public void afterConstruction(final Object thisObject, final JoinPoint.StaticPart jp) { if (!CTRLINST.isMonitoringEnabled()) { return; } final Signature signature = jp.getSignature(); if (!CTRLINST.isProbeActivated(this.signatureToLongString(signature))) { return; } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final ConstructionEvent crecord = new ConstructionEvent(TIME.getTime(), trace.getTraceId(), trace.getNextOrderId(), signature.getDeclaringTypeName(), System.identityHashCode(thisObject)); CTRLINST.newMonitoringRecord(crecord); } }
/** * This is an advice which will be used after the construction of an object. * * @param thisObject * @param jp * The static information about this joint point. */ // HINT: This may be logged multiple times due to super constructor calls... @AfterReturning("monitoredConstructor() && this(thisObject) && notWithinKieker()") public void afterConstruction(final Object thisObject, final JoinPoint.StaticPart jp) { if (!CTRLINST.isMonitoringEnabled()) { return; } final Signature signature = jp.getSignature(); if (!CTRLINST.isProbeActivated(this.signatureToLongString(signature))) { return; } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final ConstructionEvent crecord = new ConstructionEvent(TIME.getTime(), trace.getTraceId(), trace.getNextOrderId(), signature.getDeclaringTypeName(), System.identityHashCode(thisObject)); CTRLINST.newMonitoringRecord(crecord); } }
@Before("monitoredOperation() && notWithinKieker()") public void beforeOperation(final StaticPart jpStaticPart) { if (!CTRLINST.isMonitoringEnabled()) { return; } final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature()); if (!CTRLINST.isProbeActivated(operationSignature)) { return; } TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); // TO-DO parent trace is never used, so reduce impl. (chw) CTRLINST.newMonitoringRecord(trace); } // long threadId = Thread.currentThread().getId(); // int orderIndex = currentOrderIndex.get().incrementValue(); // int stackIndex = this.currentStackIndex.get().incrementValue(); final long traceId = trace.getTraceId(); final String typeName = jpStaticPart.getSignature().getDeclaringTypeName(); // measure before execution CTRLINST.newMonitoringRecord( new BeforeOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, typeName)); }
/** * Checks if the given parameter has the same origin and source location as * the {@link DrawStatement}. * * @param otherJpInfo * the other Joinpoint info * @return true, if successful */ public boolean hasSameSignatureAs(final StaticPart otherJpInfo) { if (this.jpInfo == null) { return false; } switch (type) { case CREATE_MESSAGE: if (!(otherJpInfo.getSignature() instanceof ConstructorSignature)) { return false; } break; case MESSAGE: if (!(otherJpInfo.getSignature() instanceof MethodSignature)) { return false; } break; default: break; } return this.jpInfo.getSignature().toLongString().equals(otherJpInfo.getSignature().toLongString()); }
public ConfigAttributeDefinition getAttributes(Object object) throws IllegalArgumentException { Assert.notNull(object, "Object cannot be null"); if (object instanceof MethodInvocation) { return this.lookupAttributes(((MethodInvocation) object).getMethod()); } if (object instanceof JoinPoint) { JoinPoint jp = (JoinPoint) object; Class targetClazz = jp.getTarget().getClass(); String targetMethodName = jp.getStaticPart().getSignature().getName(); Class[] types = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes(); if (logger.isDebugEnabled()) { logger.debug("Target Class: " + targetClazz); logger.debug("Target Method Name: " + targetMethodName); for (int i = 0; i < types.length; i++) { if (logger.isDebugEnabled()) { logger.debug("Target Method Arg #" + i + ": " + types[i]); } } } try { return this.lookupAttributes(targetClazz.getMethod(targetMethodName, types)); } catch (NoSuchMethodException nsme) { throw new IllegalArgumentException("Could not obtain target method from JoinPoint: " + jp); } } throw new IllegalArgumentException("Object must be a MethodInvocation or JoinPoint"); }
public int vote(Authentication authentication, Object object, Collection attributes) { int result = ACCESS_ABSTAIN; for (ConfigAttribute attribute : (Collection<ConfigAttribute>)attributes) { if (this.supports(attribute)) { Object[] args; Class<?>[] params; if (object instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) object; params = invocation.getMethod().getParameterTypes(); args = invocation.getArguments(); } else { JoinPoint jp = (JoinPoint) object; params = ((CodeSignature) jp.getStaticPart().getSignature()) .getParameterTypes(); args = jp.getArgs(); } List<Sid> sids = sidRetrievalStrategy.getSids(authentication); injectIntoCriteria(sids, params, args); return result; } } return result; }
@Before("monitoredOperation() && notWithinKieker()") public void beforeOperation(final StaticPart jpStaticPart) { if (!CTRLINST.isMonitoringEnabled()) { return; } final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature()); if (!CTRLINST.isProbeActivated(operationSignature)) { return; } TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); // TO-DO parent trace is never used, so reduce impl. (chw) CTRLINST.newMonitoringRecord(trace); } // long threadId = Thread.currentThread().getId(); // int orderIndex = currentOrderIndex.get().incrementValue(); // int stackIndex = this.currentStackIndex.get().incrementValue(); final long traceId = trace.getTraceId(); final String typeName = jpStaticPart.getSignature().getDeclaringTypeName(); // measure before execution CTRLINST.newMonitoringRecord( new BeforeOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, typeName)); }
protected Object[] getDomainObjectInstances(Object secureObject) { List<Object> result = new ArrayList<Object>(); Object[] args; Class<?>[] params; if (secureObject instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) secureObject; params = invocation.getMethod().getParameterTypes(); args = invocation.getArguments(); } else { JoinPoint jp = (JoinPoint) secureObject; params = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes(); args = jp.getArgs(); } for (int i = 0; i < params.length; i++) { if (getProcessDomainObjectClass().isAssignableFrom(params[i])) { result.add(args[i]); } } if (result.size() == 0) { throw new AuthorizationServiceException("Secure object: " + secureObject + " did not provide any argument of type: " + getProcessDomainObjectClass()); } return result.toArray(new Object[0]); }
@Before("monitoredOperation() && notWithinKieker()") public void beforeOperation(final StaticPart jpStaticPart) { if (!CTRLINST.isMonitoringEnabled()) { return; } final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature()); if (!CTRLINST.isProbeActivated(operationSignature)) { return; } Long threadId = this.threadLocalId.get(); if (null == threadId) { threadId = this.idGenerator.getNewId(); this.threadLocalId.set(threadId); // CTRLINST.newMonitoringRecord(new TraceMetadata(-1, threadId, "<NO SESSION ID>", CTRLINST.getHostname(), -1, -1)); CTRLINST.newMonitoringRecord(new ThreadMetaData(CTRLINST.getHostname(), threadId)); } final int orderIndex = this.currentOrderIndex.get().incrementValue(); final String typeName = jpStaticPart.getSignature().getDeclaringTypeName(); CTRLINST.newMonitoringRecord( new BeforeThreadBasedEvent(TIME.getTime(), threadId, orderIndex, operationSignature, typeName)); }
package de.scrum_master.aspect; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; @Aspect public class JBehaveInterceptor { @Pointcut("execution(@org.jbehave.core.annotations.* * *(..))") public void jBehavePointcut() {} @Before("jBehavePointcut()") public void jBehaveAdvice(JoinPoint.StaticPart thisJoinPointStaticPart) { Method method = ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod(); for (Annotation jBehaveAnnotation : method.getAnnotations()) { if (jBehaveAnnotation.annotationType().getPackage().getName().equals("org.jbehave.core.annotations")) System.out.println(thisJoinPointStaticPart + " -> " + jBehaveAnnotation); } } }
protected Object getDomainObjectInstance(Object secureObject) { Object[] args; Class[] params; if (secureObject instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) secureObject; params = invocation.getMethod().getParameterTypes(); args = invocation.getArguments(); } else { JoinPoint jp = (JoinPoint) secureObject; params = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes(); args = jp.getArgs(); } for (int i = 0; i < params.length; i++) { if (processDomainObjectClass.isAssignableFrom(params[i])) { return args[i]; } } throw new AuthorizationServiceException("Secure object: " + secureObject + " did not provide any argument of type: " + processDomainObjectClass); }
@Before("monitoredOperation() && notWithinKieker()") public void beforeOperation(final StaticPart jpStaticPart) { if (!CTRLINST.isMonitoringEnabled()) { return; } final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature()); if (!CTRLINST.isProbeActivated(operationSignature)) { return; } Long threadId = this.threadLocalId.get(); if (null == threadId) { threadId = this.idGenerator.getNewId(); this.threadLocalId.set(threadId); // CTRLINST.newMonitoringRecord(new TraceMetadata(-1, threadId, "<NO SESSION ID>", CTRLINST.getHostname(), -1, -1)); CTRLINST.newMonitoringRecord(new ThreadMetaData(CTRLINST.getHostname(), threadId)); } final int orderIndex = this.currentOrderIndex.get().incrementValue(); final String typeName = jpStaticPart.getSignature().getDeclaringTypeName(); CTRLINST.newMonitoringRecord( new BeforeThreadBasedEvent(TIME.getTime(), threadId, orderIndex, operationSignature, typeName)); }
public final boolean collect(CollectionAspectProperties aspect, JoinPoint.StaticPart target) { Signature sig = target.getSignature(); Class<?> clazz = sig.getDeclaringType(); String methodName = sig.getName(); String classMethod = clazz.getName() + "." + methodName; Boolean keepFullMethod = knownTargets.get(classMethod); if (keepFullMethod == null) { String pluginName = aspect.getPluginName(); if (StringUtil.isEmpty(pluginName)) pluginName = "unknown"; knownTargets.put(classMethod, Boolean.TRUE); CollectionSettingName settingName=getMethodSettingName(clazz, pluginName, methodName); registry.register(settingName, Boolean.TRUE); return true; } if (keepFullMethod.booleanValue()) { return true; } else { return false; } }