use of org.aspectj.lang.JoinPoint in project commons by craftercms.
the class ValidateParamsAspect method doValidation.
@Before("@within(org.craftercms.commons.validation.annotations.param.ValidateParams) || " + "@annotation(org.craftercms.commons.validation.annotations.param.ValidateParams)")
public void doValidation(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
Method method = AopUtils.getActualMethod(joinPoint);
Annotation[][] allParamAnnotations = method.getParameterAnnotations();
ValidationResult result = new ValidationResult(errorMessageBundle);
if (ArrayUtils.isNotEmpty(allParamAnnotations)) {
for (int i = 0; i < args.length; i++) {
Object param = args[i];
Annotation[] paramAnnotations = allParamAnnotations[i];
for (Annotation annotation : paramAnnotations) {
validateParam(annotation, param, result);
}
}
}
if (result.hasErrors()) {
String methodStr = method.toGenericString();
result.setMessage(ValidationUtils.getErrorMessage(errorMessageBundle, INVALID_METHOD_PARAMS_ERROR_CODE, methodStr));
throw new ValidationRuntimeException(result);
}
}
use of org.aspectj.lang.JoinPoint in project spring-security by spring-projects.
the class AspectJMethodSecurityInterceptorTests method setUp.
@BeforeEach
public final void setUp() {
MockitoAnnotations.initMocks(this);
SecurityContextHolder.clearContext();
this.token = new TestingAuthenticationToken("Test", "Password");
this.interceptor = new AspectJMethodSecurityInterceptor();
this.interceptor.setAccessDecisionManager(this.adm);
this.interceptor.setAuthenticationManager(this.authman);
this.interceptor.setSecurityMetadataSource(this.mds);
// Set up joinpoint information for the countLength method on TargetObject
// new MockJoinPoint(new
this.joinPoint = mock(ProceedingJoinPoint.class);
// TargetObject(), method);
Signature sig = mock(Signature.class);
given(sig.getDeclaringType()).willReturn(TargetObject.class);
JoinPoint.StaticPart staticPart = mock(JoinPoint.StaticPart.class);
given(this.joinPoint.getSignature()).willReturn(sig);
given(this.joinPoint.getStaticPart()).willReturn(staticPart);
CodeSignature codeSig = mock(CodeSignature.class);
given(codeSig.getName()).willReturn("countLength");
given(codeSig.getDeclaringType()).willReturn(TargetObject.class);
given(codeSig.getParameterTypes()).willReturn(new Class[] { String.class });
given(staticPart.getSignature()).willReturn(codeSig);
given(this.mds.getAttributes(any())).willReturn(SecurityConfig.createList("ROLE_USER"));
given(this.authman.authenticate(this.token)).willReturn(this.token);
}
use of org.aspectj.lang.JoinPoint in project Asqatasun by Asqatasun.
the class EALoggerImpl method logMethodEntry.
/*
* Cette méthode est appelée à chaque fois (et avant) qu'une méthode du
* package org.asqatasun.service.* est interceptée
*/
public void logMethodEntry(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
// Nom de la méthode interceptée
String name = joinPoint.getSignature().toLongString();
StringBuffer sb = new StringBuffer("ENTERING " + name + " called with: [");
// Liste des valeurs des arguments reçus par la méthode
for (int i = 0; i < args.length; i++) {
Object o = args[i];
sb.append("'");
sb.append(o);
sb.append("'");
sb.append((i == args.length - 1) ? "" : ", ");
}
sb.append("]");
LOGGER.info(getHostname() + " - " + sb);
timeMap.put(name, System.currentTimeMillis());
}
use of org.aspectj.lang.JoinPoint in project PhotoNoter by yydcdut.
the class PermissionAspect method afterPermissionRequestBack.
@After("execution(* android.support.v4.app.FragmentActivity.onRequestPermissionsResult(..))")
public void afterPermissionRequestBack(JoinPoint joinPoint) {
YLog.i(TAG, "afterPermissionRequestBack");
Object[] objects = joinPoint.getArgs();
Object object = joinPoint.getTarget();
if (objects.length >= 1 && objects[0] instanceof Integer && object != null && object instanceof IView && ((IView) object).getPresenter() != null) {
int requestCode = (int) objects[0];
invokeMethod(((IView) object).getPresenter(), requestCode);
} else {
YLog.i(TAG, "afterPermissionRequestBack --> bad");
}
}
use of org.aspectj.lang.JoinPoint in project sakuli by ConSol.
the class ModifySahiTimerAspectTest method testDetermineDelay.
@Test
public void testDetermineDelay() throws Exception {
BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
when(loader.getSahiProxyProperties().getRequestDelayMs()).thenReturn(500);
loader.getActionProperties().setTypeDelay(0.05);
JoinPoint joinPoint = mock(JoinPoint.class);
Signature signature = mock(Signature.class);
when(joinPoint.getSignature()).thenReturn(signature);
when(signature.getName()).thenReturn("pasteSomething");
assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 500);
when(signature.getName()).thenReturn("typeMasked");
when(joinPoint.getArgs()).thenReturn(new String[] { "1", "MOD" });
assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 550);
when(joinPoint.getArgs()).thenReturn(new String[] { "12characters", "MOD" });
assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 12 * 550);
}
Aggregations