adviceInvocationArgs[this.joinPointStaticPartArgumentIndex] = jp.getStaticPart(); numBound++;
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 + "'"); } }
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()); } });
@Before("@annotation(com.company.annotation.AuthorizeUser") public void isAuthorized(JoinPoint jp) { Class<?> returnType = ((MethodSignature)jp.getStaticPart() .getSignature()).getReturnType(); if(returnType == String.class) ... else ... }
@Override public JoinPoint.StaticPart getStaticPart() { return this.joinpoint.getStaticPart(); }
@Override public JoinPoint.StaticPart getStaticPart() { return this.joinpoint.getStaticPart(); }
private String getOperationName(final JoinPoint joinPoint) { MethodSignature methodSig = (MethodSignature) joinPoint .getStaticPart() .getSignature(); Method method = methodSig.getMethod(); Profiled annotation = method.getAnnotation(Profiled.class); return annotation.value(); }
public SourceCodeLocation getSourceCodeLocation(JoinPoint jp) { return getSourceCodeLocation(jp.getStaticPart()); }
public static SourceCodeLocation getSourceCodeLocation(JoinPoint jp) { return getSourceCodeLocation(jp.getStaticPart()); }
/** * Break down a JoinPoint into some fields which are commonly used. */ public static JoinPointBreakDown breakDown(JoinPoint jp) { return breakDown(jp, getSourceCodeLocation(jp.getStaticPart())); }
/** * This is the closing method of {@link #execute(JoinPoint)}. After an * execution joinpoint has ended we must complete the diagram with the * return message. * * @param execution * the execution joinpoint * @param returnValue * the return value * @since 1.6 (03.06.2015) */ public void returnFromExecute(final JoinPoint execution, final Object returnValue) { String senderName = getCallerNameOf(execution); String targetName = getTargetName(execution); String caller = this.callerNames.pop(); LOG.trace("Caller '{}' was taken from stack.", caller); assert caller.equals(senderName) : "'" + senderName + "' was not on top of stack " + this.callerNames; this.addReturnMessage(senderName, targetName, returnValue, execution.getStaticPart()); }
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); }
/** * Logs the return arrow from the last call to the generated sequence * diagram. Because it could be that the return message is already logged by * an execution joinpoint we check that first. * * @param call * the call * @param returnValue * the return value */ public void returnMessage(final JoinPoint call, final Object returnValue) { DrawStatement stmt = this.getLastMessage(); if (stmt.isFromExecutionJoinpoint() && stmt.hasSameSignatureAs(call.getStaticPart())) { LOG.debug("Joinpoint '{}' is logged already as call.", call); return; } this.returnMessage(call.getTarget(), returnValue, call.getStaticPart()); }
/** * Logs the call of a method to the generated sequence diagram. * * @param caller * the caller * @param call * the call */ public void message(final Object caller, final JoinPoint call) { this.message(caller, call.getTarget(), call.getStaticPart(), call.getArgs()); }
@Before("validateObjectPointCut()") public void validateObjectAroundAction(JoinPoint jp) throws Throwable { ValidateSingleArgument annotation = ((MethodSignature) jp.getStaticPart().getSignature()) .getMethod().getAnnotation(ValidateSingleArgument.class); int requestIndex = annotation.requestIndex(); // Get a reference to the object to be validated. Object obj = (jp.getArgs()[requestIndex]); // Validate. ValidationErrors errors = validationUtil.validate(obj); if (errors.getValidationErrors().size() > 0) { throw new QValidationException(errors); } } }
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 + "'"); } }
/** * Logs the creation of an object in the created sequence diagram. * * @param call * the call * @param result * the created object */ public void createMessage(final JoinPoint call, final Object result) { Object creator = call.getThis(); if (creator == null) { String classname = JoinPointHelper.getCallerOf(call).getClassName(); try { creator = Class.forName(classname); } catch (ClassNotFoundException ex) { throw new NotFoundException(classname, ex); } } this.createMessage(creator, result, call.getStaticPart()); }
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 + "'"); } }
public static final JoinPoint createMockJoinPoint (Method method) { SourceLocation source=createMockSourceLocation(method); Signature sig=createMockMethodSignature(method); JoinPoint.StaticPart staticPart=Mockito.mock(JoinPoint.StaticPart.class); Mockito.when(staticPart.getSignature()).thenReturn(sig); Mockito.when(staticPart.getSourceLocation()).thenReturn(source); JoinPoint jp=Mockito.mock(JoinPoint.class); Mockito.when(jp.getStaticPart()).thenReturn(staticPart); Mockito.when(jp.getSignature()).thenReturn(sig); Mockito.when(jp.getSourceLocation()).thenReturn(source); return jp; }