【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“AuthoryInterceptor.java”一文,供大家参考学习!
package struts2.interceptors;
import java.util.Map;
import struts2.actions.Role;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class AuthoryInterceptor extends AbstractInterceptor {
public String intercept(ActionInvocation ai) throws Exception {
Map session = ai.getInvocationContext().getSession();
String role = (String) session.get("ROLE");
if (role != null) {
Object obj = ai.getAction();
if (obj instanceof Role) {
Role action = (Role) obj;
action.setRole(role);
}
return ai.invoke();
} else {
return Action.LOGIN;
}
}
}