use of org.aspectj.lang.JoinPoint in project spring-framework by spring-projects.
the class AbstractAspectJAdvice method currentJoinPoint.
/**
* Lazily instantiate joinpoint for the current invocation.
* Requires MethodInvocation to be bound with ExposeInvocationInterceptor.
* <p>Do not use if access is available to the current ReflectiveMethodInvocation
* (in an around advice).
* @return current AspectJ joinpoint, or through an exception if we're not in a
* Spring AOP invocation.
*/
public static JoinPoint currentJoinPoint() {
MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
if (!(mi instanceof ProxyMethodInvocation)) {
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
}
ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY);
if (jp == null) {
jp = new MethodInvocationProceedingJoinPoint(pmi);
pmi.setUserAttribute(JOIN_POINT_KEY, jp);
}
return jp;
}
use of org.aspectj.lang.JoinPoint in project weixin-java-mp-multi-demo by binarywang.
the class ControllerLogAspect method writeParams.
@Before("controller()")
public void writeParams(JoinPoint jp) {
String[] names = ((CodeSignature) jp.getSignature()).getParameterNames();
Object[] args = jp.getArgs();
if (ArrayUtils.isEmpty(names)) {
return;
}
StringBuilder sb = new StringBuilder("Arguments: ");
for (int i = 0; i < names.length; i++) {
sb.append(names[i] + " = " + args[i] + ",");
}
debugInController(jp, sb.toString());
}
use of org.aspectj.lang.JoinPoint in project Corgi by kevinYin.
the class AdminLoggerAspect method getJointPointParam.
/**
* 获取连接点对应方法的请求参数列表(参数名-参数值)
*
* @param jp
* - 切面连接点
* @return
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
public static Map<String, Object> getJointPointParam(JoinPoint jp) throws IllegalArgumentException, IllegalAccessException {
MethodSignature ms = (MethodSignature) jp.getSignature();
Method method = ms.getMethod();
List<Class<?>> paramTypes = Arrays.asList(method.getParameterTypes());
List<String> paramNames = getMethodParamNames(method);
Object[] args = jp.getArgs();
int size = paramNames.size();
int length = args.length;
Map<String, Object> params = new HashMap<String, Object>();
for (int i = 0; i < size && i < length; i++) {
Class<?> clazz = paramTypes.get(i);
String name = paramNames.get(i);
Object value = args[i];
if (isJavaClass(clazz)) {
params.put(name, value);
} else {
if ((value instanceof HttpServletResponse)) {
continue;
}
Map<String, Object> param = getClassAttrValueMap(clazz, name, value);
params.putAll(param);
}
}
return params;
}
use of org.aspectj.lang.JoinPoint in project spf4j by zolyfarkas.
the class SamplingAllocationMonitorAspect method afterAllocation.
@AfterReturning(pointcut = "call(*.new(..))", returning = "obj", argNames = "jp,obj")
public void afterAllocation(final JoinPoint jp, final Object obj) {
MutableInteger counter = ThreadLocalCounter.get();
int value = counter.getValue();
if (value < SAMPLE_COUNT) {
counter.setValue(value + 1);
} else {
// the stack trace get and the object size method are expensive to be done at every allocation...
counter.setValue(0);
StackTrace st = StackTrace.from(Thread.currentThread().getStackTrace(), 2);
RECORDER.getRecorder(st).record(InstrumentationHelper.getObjectSize(obj));
}
}
use of org.aspectj.lang.JoinPoint in project herd by FINRAOS.
the class NamespaceSecurityAdviceTest method checkPermissionAssertNoExceptionWhenMultipleAnnotationsAndAllPermissionsValid.
/**
* Test where a method is annotated with multiple NamespacePermission annotations. Asserts that the user will all permissions do not throw an exception.
*/
@Test
public void checkPermissionAssertNoExceptionWhenMultipleAnnotationsAndAllPermissionsValid() throws Exception {
// Mock a join point of the method call
// mockMethodMultipleAnnotations("foo", "bar");
JoinPoint joinPoint = mock(JoinPoint.class);
MethodSignature methodSignature = mock(MethodSignature.class);
Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethodMultipleAnnotations", String.class, String.class);
when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace1", "namespace2" });
when(methodSignature.getMethod()).thenReturn(method);
when(joinPoint.getSignature()).thenReturn(methodSignature);
when(joinPoint.getArgs()).thenReturn(new Object[] { "foo", "bar" });
String userId = "userId";
ApplicationUser applicationUser = new ApplicationUser(getClass());
applicationUser.setUserId(userId);
applicationUser.setNamespaceAuthorizations(new HashSet<>());
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("foo", Arrays.asList(NamespacePermissionEnum.READ)));
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("bar", Arrays.asList(NamespacePermissionEnum.WRITE)));
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null));
try {
namespaceSecurityAdvice.checkPermission(joinPoint);
} catch (AccessDeniedException e) {
fail();
}
}
Aggregations