提问:使用spring aop实现权限管理

06-03-08 wzw9258
本人在用struts+spring+hibernate,不想用acegi.

在用spring aop做权限管理时,代码如下

[code

AuthenticationInterceptor.java

public class AuthenticationInterceptor implements MethodBeforeAdvice {

public void before(Method parm1, Object[] parm2, Object parm3) throws java.lang.Throwable {

if(!authentication.canExceute()){

throw new AuthenticationException(" exception start===");

}

}

}

AuthenticationException.java

public class AuthenticationException extends Exception {

public AuthenticationException(){

}

public AuthenticationException(String msg){

System.out.println("AuthenticationException==="+msg);

}

}

在执行过程中出现如下:

javax.servlet.ServletException

org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)

org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)

javax.servlet.http.HttpServlet.service(HttpServlet.java:743)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

com.zd.dmis.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:70)

org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

root cause

com.zd.dmis.exception.AuthenticationException

com.zd.dmis.interceptor.AuthenticationInterceptor.before(AuthenticationInterceptor.java:26)

org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)

org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)

org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:110)

org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)

org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:606)

com.zd.dmis.struts.action.manager.RoleAction$$EnhancerByCGLIB$$ebc682fd.execute(<generated>)

org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)

org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)

javax.servlet.http.HttpServlet.service(HttpServlet.java:743)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

com.zd.dmis.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:70)

org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

上过错误是在AuthenticationInterceptor的before方法的throw new AuthenticationException(" exception start==="); 出现的,

我如何能够根据AuthenticationInterceptor的before方法中如果没有权限,能够转向一个页面,以便显示直接提示信息,谢谢各位!

Y04069
2007-03-27 17:29
如果拦截方法的参数中包含response,直接response.redirect()

猜你喜欢