package com.mmall.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import com.mmall.common.ResponseCode;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.User;
import com.mmall.service.IUserService;
public class AuthorityProxy implements InvocationHandler {
private Object target;
private Object obj;
private IUserService iUserService;
public AuthorityProxy(Object obj, IUserService iUserService) {
this.obj = obj;
this.iUserService = iUserService;
}
public Object bind(Object target) {
this.target = target;
return Proxy.newProxyInstance(target.getClass().getClassLoader(),
target.getClass().getInterfaces(), this);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (obj instanceof User) {
if (iUserService.checkAdminRole((User) obj).isSuccess()) {
return method.invoke(target, args);
}
return ServerResponse.createByErrorMessage("无权限操作");
}
return ServerResponse.createByErrorCodeMessage(
ResponseCode.NEED_LOGIN.getCode(), "用户未登录,请登录管理员");
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦