//得到当前登录的用户
Employee e = (Employee) ActionContext.getContext().getSession().get("loginUser");
//遍历当前用户下的所有的权限组
for(PrivilegeGroup group : e.getGroups()){
//如果该权限组下包含,要访问该方法所需要的权限,就放行
if(group.getPrivileges().contains(methodPrivilege)){
return true;
}
}
//说明遍历的该用户所有的权限组,没有发现该权限,说明没有该权限
return false;
}
//没有标注注解,表示谁都可以调用该方法
return true;
}
private boolean validate(ActionInvocation invocation) throws SecurityException, NoSuchMethodException {
String methodName=invocation.getProxy().getMethod();
Method currentMethod = invocation.getAction().getClass().getMethod(methodName);
//得到方法上的注解
Permission permission = currentMethod.getAnnotation(Permission.class);
//该方法上的所需要的权限
SystemPrivilege methodPrivilege = new SystemPrivilege(new SystemPrivilegePK(permission.module(), permission.privilege()));
//得到当前登录的用户
Employee e = (Employee) ActionContext.getContext().getSession().get("loginUser");
//遍历当前用户下的所有的权限组
for(PrivilegeGroup group : e.getGroups()){
//如果该权限组下包含,要访问该方法所需要的权限,就放行
if(group.getPrivileges().contains(methodPrivilege)){
return true;
}
}
//说明遍历的该用户所有的权限组,没有发现该权限,说明没有该权限
return false;
}
//没有标注注解,表示谁都可以调用该方法
return true;
}