/**
* 访问拦截
* @author:Nemo 2017年04月24日
*/
@Aspect
@Component
public class AuthAop {
private final Logger logger = Logger.getLogger(getClass());
/**
* 定义切点,所有的controller下的访问都拦截
*/
@Pointcut("execution( * com.nemo.backend.controller..*(..))")
public void pointCutAt() {}
@Before("pointCutAt()")
public void beforeAction(JoinPoint point) throws OmegaException, NoSuchMethodException {
Class cls = point.getSignature().getDeclaringType();
boolean isNoCheckAuth = cls.isAnnotationPresent(NoCheckAuth.class);
if(isNoCheckAuth){
//类名前注解
Annotation noCheckAuth = cls.getAnnotation(NoCheckAuth.class);
}
//拦截的方法名称
String methodName = point.getSignature().getName();
//拦截的放参数类型
Class[] parameterTypes = ((MethodSignature)point.getSignature()).getMethod().getParameterTypes();
Method method = point.getSignature().getDeclaringType().getMethod(methodName,parameterTypes);
isNoCheckAuth = method.isAnnotationPresent(NoCheckAuth.class);
//如果方法前注解为不拦截登录
if(isNoCheckAuth){
//方法前的注释
NoCheckAuth noCheckAuth = method.getAnnotation(NoCheckAuth.class);
}
}
}