Search in sources :

Example 26 with JoinPoint

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);
    }
}
Also used : Method(java.lang.reflect.Method) ValidationRuntimeException(org.craftercms.commons.validation.ValidationRuntimeException) ValidationResult(org.craftercms.commons.validation.ValidationResult) JoinPoint(org.aspectj.lang.JoinPoint) Annotation(java.lang.annotation.Annotation) Before(org.aspectj.lang.annotation.Before)

Example 27 with JoinPoint

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);
}
Also used : CodeSignature(org.aspectj.lang.reflect.CodeSignature) Signature(org.aspectj.lang.Signature) CodeSignature(org.aspectj.lang.reflect.CodeSignature) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with JoinPoint

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());
}
Also used : JoinPoint(org.aspectj.lang.JoinPoint)

Example 29 with JoinPoint

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");
    }
}
Also used : IView(com.yydcdut.note.views.IView) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) After(org.aspectj.lang.annotation.After)

Example 30 with JoinPoint

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);
}
Also used : Signature(org.aspectj.lang.Signature) BaseActionLoader(org.sakuli.loader.BaseActionLoader) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Aggregations

JoinPoint (org.aspectj.lang.JoinPoint)59 MethodSignature (org.aspectj.lang.reflect.MethodSignature)31 Method (java.lang.reflect.Method)30 Test (org.junit.Test)29 AccessDeniedException (org.springframework.security.access.AccessDeniedException)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)25 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)21 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)14 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)11 Before (org.aspectj.lang.annotation.Before)5 CodeSignature (org.aspectj.lang.reflect.CodeSignature)4 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 IView (com.yydcdut.note.views.IView)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2