⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 powercontrolaspect.java

📁 达内Java培训实训项目ECPORT原码。 包括逐步优化的四个版本: 简单工厂模式实现 简单Spring-IoC实现 Spring声明式事务实现 Spring-AOP集成
💻 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 + -