Android Open Source - AspectJ-Android-Example Authentication Aspect






From Project

Back to project page AspectJ-Android-Example.

License

The source code is released under:

Apache License

If you think the Android project AspectJ-Android-Example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package android.mobile.peakgames.net.aspectjandroid.aspect;
//from   w ww.  j a v a  2s. co m
import android.mobile.peakgames.net.aspectjandroid.Session;
import android.mobile.peakgames.net.aspectjandroid.exception.AuthenticationException;
import android.util.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import java.util.HashSet;
import java.util.Set;

@Aspect
public class AuthenticationAspect {
    private static final String TAG = AuthenticationAspect.class.getName();

    private static final Set<String> AUTH_NAMES = new HashSet<String>();

    static {
        AUTH_NAMES.add("peak");
    }

    @Pointcut("execution(* android.mobile.peakgames.net.aspectjandroid.AspectActivity.*Auth*(..)) || execution(@android.mobile.peakgames.net.aspectjandroid.SecureMethod * *(..))")
    public void authenticateEntryPoint() {
    }

    @Around("authenticateEntryPoint()")
    public void authenticateMethod(ProceedingJoinPoint joinPoint) {
        if (AUTH_NAMES.contains(Session.getInstance().getName())) {
            Log.d(TAG, "Authenticate successfully");
        } else {
            Log.e(TAG, "User : " + Session.getInstance().getName() + " is not authenticated");
            throw new AuthenticationException();
        }
    }
}




Java Source Code List

android.mobile.peakgames.net.aspectjandroid.ApplicationTest.java
android.mobile.peakgames.net.aspectjandroid.AspectActivity.java
android.mobile.peakgames.net.aspectjandroid.SecureMethod.java
android.mobile.peakgames.net.aspectjandroid.Session.java
android.mobile.peakgames.net.aspectjandroid.aspect.AuthenticationAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.CachingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.ExceptionHandlingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.LoggingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.ProfilingAspect.java
android.mobile.peakgames.net.aspectjandroid.exception.AuthenticationException.java