spring-security模块实现了权限控制功能.
自定义过滤器
1.自定义一个类实现Interceptor接口.
2.配置在调用的action中.并且加入默认的过滤器栈.只要你要使用默认的过滤器栈.
自定义过滤器
1.自定义一个类实现Interceptor接口.
2.配置在调用的action中.并且加入默认的过滤器栈.只要你要使用默认的过滤器栈.
<interceptors>
<interceptor name="auth" class="com.meiyoudao.filter.AuthFilter"></interceptor>
</interceptors>
<action name="welcome" class="com.meiyoudao.action.WelcomeAction">
<interceptor-ref name="auth"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>/welcome.jsp</result>
</action>
/**
*
*/
package com.meiyoudao.filter;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
/**
* @author meiyoudao
*
*/
public class AuthFilter implements Interceptor {
/* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#init()
*/
public void init() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
*/
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("do something filter begin...");
String str = invocation.invoke();
System.out.println("do something filter end...");
return str;
}
}
本文介绍了一个基于Spring Security的权限控制系统实现。通过自定义过滤器实现对特定Action的拦截,该过滤器打印开始和结束的日志信息。此方法适用于需要进行用户权限验证的Web应用。
1011

被折叠的 条评论
为什么被折叠?



