我有这个 struts2 拦截器类,它检查access
会话密钥并决定是让用户继续查看实际页面还是显示错误消息页面。
这种价值检查的最佳方法是什么?
public String intercept(ActionInvocation invoke) throws Exception {
Map<String,Object> session = invoke.getInvocationContext().getSession();
Set<String> access = (Set<String>) session.get("access");
String action = invoke.getAction().getClass().getSimpleName();
switch(action) {
case "ParametersHomeAction":
case "ErrorMapAction" :
case "FillerMusicAndLoginAction":
case "ScheduledAction":
case "SysConfigAction":
case "SysParamAction":
if(access.contains("PAR-FM") ||
access.contains("PAR-SCHA") ||
access.contains("PAR-EM") ||
access.contains("PAR-SYSCNF") ||
access.contains("PAR-CSAT")) {
return invoke.invoke();
} else return RESTRICTED_ERROR;
case "ProfilesHomeAction":
case "GroupAction":
case "UserAction":
if(access.contains("PFA-U") ||
access.contains("PFA-G")) {
return invoke.invoke();
} else return RESTRICTED_ERROR;
case "SystemHomeAction":
case "FunctionAction":
case "LockUnlockAction":
case "WfCategoryAction":
case "WfStatusAction":
if(access.contains("SYSA-WC") ||
access.contains("SYSA-WS") ||
access.contains("SYSA-WT") ||
access.contains("SYSA-WTU") ||
access.contains("SYSA-LUU") ||
access.contains("SYSA-BF")) {
return invoke.invoke();
} else return RESTRICTED_ERROR;
case "ReportsHomeAction":
if(access.contains("RP-BOAL") ||
access.contains("RP-PBAL") ||
access.contains("RP-PBF") ||
access.contains("RP-PBMT") ||
access.contains("RP-IVRMU") ||
access.contains("RP-ACAR") ||
access.contains("RP-AUR")) {
return invoke.invoke();
} else return RESTRICTED_ERROR;
// TRANSACTIONS TO FOLLOW
case "HomeAction": invoke.invoke();
default: return RESTRICTED_ERROR;
}
}