📄 powercontrolaspect.java
字号:
package com.royee.ecport.aop;
import org.aspectj.lang.JoinPoint;
import com.royee.ecport.annotation.Limit;
import com.royee.ecport.enums.Role;
import com.royee.ecport.exception.ApplicationNotRunningException;
import com.royee.ecport.exception.NoPowerException;
import com.royee.ecport.pojo.User;
import com.royee.ecport.web.actions.LoginAction;
/**
* 业务级别权限控制模块,通过Limit注解在Biz层检验用户权限
* @author cfgxy
*
*/
public class PowerControlAspect extends AspectFilter {
public void doFilter(JoinPoint jp) {
try {
// 获取Limit注解
Limit annLimit = getAnnotation(jp, Limit.class);
if(annLimit==null)
return;
Role[] rList = annLimit.value();
if(rList==null)
return;
Object u = session().getAttribute(LoginAction.SESSION_KEY);
if (u == null) {
if (Role.check(Role.GUEST, rList))
return;
logger(jp).info("Guest 访问违规!!!");
throw new NoPowerException("Guest is no power to do this.");
}
if (u.getClass().equals(User.class)) {
if (Role.check(Role.USER, rList))
return;
logger(jp).info(
"User(" + ((User) u).getUsername() + ") 访问违规!!!");
throw new NoPowerException("User is no power to do this.");
}
} catch (ApplicationNotRunningException e) {
// TODO Auto-generated catch block
logger(jp).debug("denified method used by spring.");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -