package com.philisense.www.aspect;

import com.philisense.www.access.WebRestURLSecurityMetadataSource;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 对资源权限重新加载
 *
 * @author
 */
@Aspect
@Component
public class ReLoadResourceAspect {

    @Autowired
    private WebRestURLSecurityMetadataSource webRestURLSecurityMetadataSource;

    /**
     * 配置切入点
     */
    @Pointcut(
            "execution(public * com.philisense.www.controller.*.ProResourceActionController*.delete*(..)) ||" +
            "execution(public * com.philisense.www.controller.*.ProResourceActionController*.insert*(..)) ||" +
            "execution(public * com.philisense.www.controller.*.ProResourceActionController*.update*(..)) ||" +
            "execution(public * com.philisense.www.controller.*.ProResAuthController*.delete*(..)) ||" +
            "execution(public * com.philisense.www.controller.*.ProResAuthController*.insert*(..)) ||" +
            "execution(public * com.philisense.www.controller.*.ProResAuthController*.update*(..))")
    public void reLoadResourcePointcut() {
        // 该方法无方法体,主要为了让同类中其他方法使用此切入点
    }

    /**
     * 配置环绕通知,使用在方法 reLoadResourcePointcut() 上注册的切入点
     *
     * @param joinPoint join point for advice
     */
    @Around("reLoadResourcePointcut()")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        //通过，执行下一步
        Object o = joinPoint.proceed();
        webRestURLSecurityMetadataSource.reLoadResource();
        //返回结果
        return o;
    }

}
