Search in sources :

Example 1 with CodeSignature

use of org.aspectj.lang.reflect.CodeSignature in project spring-security by spring-projects.

the class AspectJMethodSecurityInterceptorTests method setUp.

// ~ Methods
// ========================================================================================================
@Before
public final void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    SecurityContextHolder.clearContext();
    token = new TestingAuthenticationToken("Test", "Password");
    interceptor = new AspectJMethodSecurityInterceptor();
    interceptor.setAccessDecisionManager(adm);
    interceptor.setAuthenticationManager(authman);
    interceptor.setSecurityMetadataSource(mds);
    // Set up joinpoint information for the countLength method on TargetObject
    // new MockJoinPoint(new
    joinPoint = mock(ProceedingJoinPoint.class);
    // TargetObject(), method);
    Signature sig = mock(Signature.class);
    when(sig.getDeclaringType()).thenReturn(TargetObject.class);
    JoinPoint.StaticPart staticPart = mock(JoinPoint.StaticPart.class);
    when(joinPoint.getSignature()).thenReturn(sig);
    when(joinPoint.getStaticPart()).thenReturn(staticPart);
    CodeSignature codeSig = mock(CodeSignature.class);
    when(codeSig.getName()).thenReturn("countLength");
    when(codeSig.getDeclaringType()).thenReturn(TargetObject.class);
    when(codeSig.getParameterTypes()).thenReturn(new Class[] { String.class });
    when(staticPart.getSignature()).thenReturn(codeSig);
    when(mds.getAttributes(any(JoinPoint.class))).thenReturn(SecurityConfig.createList("ROLE_USER"));
    when(authman.authenticate(token)).thenReturn(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) Before(org.junit.Before)

Example 2 with CodeSignature

use of org.aspectj.lang.reflect.CodeSignature in project AndroidDevMetrics by frogermcs.

the class Dagger2GraphAnalyzer method logAndExecute.

@Around("providesMethod() || injectConstructor()")
public Object logAndExecute(ProceedingJoinPoint joinPoint) throws Throwable {
    long start = System.nanoTime();
    Object result = joinPoint.proceed();
    long stop = System.nanoTime();
    long took = TimeUnit.NANOSECONDS.toMillis(stop - start);
    if (!enabled) {
        return result;
    }
    CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature();
    Class<?> cls = codeSignature.getDeclaringType();
    if (codeSignature instanceof ConstructorSignature) {
        InitManager.getInstance().addInitMetric(cls, joinPoint.getArgs(), took);
    }
    if (isMethodWithReturnType(codeSignature)) {
        if (result != null) {
            InitManager.getInstance().addInitMetric(result.getClass(), joinPoint.getArgs(), took);
        }
    }
    return result;
}
Also used : ConstructorSignature(org.aspectj.lang.reflect.ConstructorSignature) CodeSignature(org.aspectj.lang.reflect.CodeSignature) Around(org.aspectj.lang.annotation.Around)

Example 3 with CodeSignature

use of org.aspectj.lang.reflect.CodeSignature in project hugo by JakeWharton.

the class Hugo method enterMethod.

private static void enterMethod(JoinPoint joinPoint) {
    if (!enabled)
        return;
    CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature();
    Class<?> cls = codeSignature.getDeclaringType();
    String methodName = codeSignature.getName();
    String[] parameterNames = codeSignature.getParameterNames();
    Object[] parameterValues = joinPoint.getArgs();
    StringBuilder builder = new StringBuilder("⇢ ");
    builder.append(methodName).append('(');
    for (int i = 0; i < parameterValues.length; i++) {
        if (i > 0) {
            builder.append(", ");
        }
        builder.append(parameterNames[i]).append('=');
        builder.append(Strings.toString(parameterValues[i]));
    }
    builder.append(')');
    if (Looper.myLooper() != Looper.getMainLooper()) {
        builder.append(" [Thread:\"").append(Thread.currentThread().getName()).append("\"]");
    }
    Log.v(asTag(cls), builder.toString());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        final String section = builder.toString().substring(2);
        Trace.beginSection(section);
    }
}
Also used : CodeSignature(org.aspectj.lang.reflect.CodeSignature) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Aggregations

CodeSignature (org.aspectj.lang.reflect.CodeSignature)3 JoinPoint (org.aspectj.lang.JoinPoint)2 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)2 Signature (org.aspectj.lang.Signature)1 Around (org.aspectj.lang.annotation.Around)1 ConstructorSignature (org.aspectj.lang.reflect.ConstructorSignature)1 Before (org.junit.Before)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1