All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbb.privilege.proxy.util.PrivilegeProxy Maven / Gradle / Ivy

package com.github.houbb.privilege.proxy.util;

import com.github.houbb.heaven.util.lang.ObjectUtil;
import com.github.houbb.privilege.proxy.core.impl.CglibPrivilegeProxy;
import com.github.houbb.privilege.proxy.core.impl.DynamicPrivilegeProxy;
import com.github.houbb.privilege.proxy.core.impl.NonePrivilegeProxy;

import java.lang.reflect.Proxy;

/**
 * 权限代理工具类
 * @author binbin.hou
 * @since 0.0.4
 */
public final class PrivilegeProxy {

    private PrivilegeProxy(){}

    /**
     * 获取对象代理
     * @param  泛型
     * @param object 对象代理
     * @return 代理信息
     * @since 0.0.4
     */
    @SuppressWarnings("all")
    public static  T proxy(final T object) {
        if(ObjectUtil.isNull(object)) {
            return (T) new NonePrivilegeProxy(object).proxy();
        }

        final Class clazz = object.getClass();

        // 如果targetClass本身是个接口或者targetClass是JDK Proxy生成的,则使用JDK动态代理。
        // 参考 spring 的 AOP 判断
        if (clazz.isInterface() || Proxy.isProxyClass(clazz)) {
            return (T) new DynamicPrivilegeProxy(object).proxy();
        }

        return (T) new CglibPrivilegeProxy(object).proxy();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy