【求助】Spring中的BeanNameAutoProxyCreator进行权限控制的棘手问题? 要用ApplicationContext,你用是BeanFactory吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Servlet action is not available是因为newRewardAssignmentLink没有正确生成,导致Struts找不到对应的Spring对象。而你做的修改仅对newRewardAssignmentLink的userService进行了proxy。由此看估计是userService生成不正确。我不知道你的那种Interceptor写得是不是有问题。我的拦截器一般采用实现MethodBeforeAdvice等接口来处理的。而不是实现MethodInterceptor:public class LoginInterceptor implements MethodBeforeAdvice { private static final Log logger = LogFactory.getLog(LoginInterceptor.class); private List<String> methods = new ArrayList<String>(); public void before(Method method, Object[] args, Object target) throws Throwable { boolean found = false; for (int i = 0; i < methods.size(); i++) if (methods.get(i).equals(method.getName())) { // 拦截指定的方法 found = true; break; } if (!found) return; logger.info("called service ..... " + target.getClass().getSimpleName()); HttpSession session = ((HttpServletRequest) args[1]).getSession(); IBusinessService businessService = (IBusinessService) target; businessService.setRequest((HttpServletRequest) args[1]); // 刚开始调用时即设置HttpServletRequest供工具方法调用 if (businessService.getResCode() == null) // publish功能,任何均不检测 return; if (session == null) throw new PrivilegeException("exception.login.operationTimeout"); SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(Constants.USER_KEY); if (sessionUserInfo == null) throw new PrivilegeException("exception.login.operationTimeout"); // 是否重复登陆 if (!sessionUserInfo.getSessionId().equals(session.getId())) throw new PrivilegeException("exception.login.multiUser"); // 是否有权访问该模块,000资源意味着不检测权限 if (sessionUserInfo != null && !"000".equals(businessService.getResCode())) { return; } } protected final Object getBean(String name) { return SpringContextLoaderListener.getContext().getBean(name); } public void setMethods(List<String> methods) { this.methods = methods; }} 仔细看了一下,在applicationContext.xml这个配置文件中没有找到adminService,userService 的BEAN不知你在其它文件有没有配置,拦截器代码 //取得用户Session HttpSession session = request.getSession(); //从Session中取得用户信息 User user = (User)session.getAttribute("userInfo"); Byte cropUser = user.getCorpUser(); Byte passPort = user.getPassPort(); //如果用户为企业用户,且通过审核 if(cropUser.equals((byte)1) && passPort.equals((byte)1)){ //调用目标方法,继续前进 return invocation.proceed(); }else if (cropUser.equals((byte)1) && !passPort.equals((byte)1)) { //如果是企业用户,但未通过验证 String noPassPort = "对不起,您没有通过验证,暂无权发布悬赏视频任务!"; session.setAttribute("noPassPort", noPassPort); return invocation.proceed(); //这里是否应该是用mapping.forward("");进行转发到 }else{ //如果不是企业用户 String notCorpUser = "对不起,只有企业用户才能发布悬赏视频任务!"; session.setAttribute("notCorpUser", notCorpUser); return invocation.proceed(); ////这里是否应该是用mapping.forward("");进行转发到 } } 在线等,javaMail邮件夹管理方面的问题。帮顶给分,有合理建议者多给呀! Hibernate日期数据绑定的问题 netbeans 源码下载 Hibernate批量操作的事物问题,相当奇怪,大侠请进 关于Spring 用itext在pdf中画虚线 iReport与JasperReport出PDF问题 急救!xml问题 mybatis 查询一直出异常 求助 提示下标越界 struts1.0 如何升级至struts1.1?急,急..... 我的weblogic报如下错误,困扰我一上午了,谁帮忙看看!不胜感激 如何最佳设值maxActive,maxIdle,maxWait
public class LoginInterceptor implements MethodBeforeAdvice { private static final Log logger = LogFactory.getLog(LoginInterceptor.class); private List<String> methods = new ArrayList<String>(); public void before(Method method, Object[] args, Object target) throws Throwable { boolean found = false;
for (int i = 0; i < methods.size(); i++)
if (methods.get(i).equals(method.getName())) { // 拦截指定的方法
found = true;
break;
}
if (!found)
return; logger.info("called service ..... " + target.getClass().getSimpleName()); HttpSession session = ((HttpServletRequest) args[1]).getSession(); IBusinessService businessService = (IBusinessService) target;
businessService.setRequest((HttpServletRequest) args[1]); // 刚开始调用时即设置HttpServletRequest供工具方法调用 if (businessService.getResCode() == null) // publish功能,任何均不检测
return; if (session == null)
throw new PrivilegeException("exception.login.operationTimeout"); SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(Constants.USER_KEY); if (sessionUserInfo == null)
throw new PrivilegeException("exception.login.operationTimeout"); // 是否重复登陆
if (!sessionUserInfo.getSessionId().equals(session.getId()))
throw new PrivilegeException("exception.login.multiUser"); // 是否有权访问该模块,000资源意味着不检测权限
if (sessionUserInfo != null && !"000".equals(businessService.getResCode())) {
return;
}
} protected final Object getBean(String name) {
return SpringContextLoaderListener.getContext().getBean(name);
} public void setMethods(List<String> methods) {
this.methods = methods;
}
}
拦截器代码
//取得用户Session
HttpSession session = request.getSession();
//从Session中取得用户信息
User user = (User)session.getAttribute("userInfo");
Byte cropUser = user.getCorpUser();
Byte passPort = user.getPassPort();
//如果用户为企业用户,且通过审核
if(cropUser.equals((byte)1) && passPort.equals((byte)1)){
//调用目标方法,继续前进
return invocation.proceed();
}else if (cropUser.equals((byte)1) && !passPort.equals((byte)1)) {
//如果是企业用户,但未通过验证
String noPassPort = "对不起,您没有通过验证,暂无权发布悬赏视频任务!";
session.setAttribute("noPassPort", noPassPort);
return invocation.proceed(); //这里是否应该是用mapping.forward("");进行转发到
}else{
//如果不是企业用户
String notCorpUser = "对不起,只有企业用户才能发布悬赏视频任务!";
session.setAttribute("notCorpUser", notCorpUser);
return invocation.proceed(); ////这里是否应该是用mapping.forward("");进行转发到 }
}