已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
日志攔截器package erceptor;import java.util.Date;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import erceptor.AbstractInterceptor;import com.yuanit.app.action.AdminAction;import com.yuanit.app.model.Log;import com.yuanit.app.model.Member;import com.yuanit.app.model.Permission;import com.yuanit.app.model.Role;import com.yuanit.app.service.ILogService;import com.yuanit.app.service.IMemberService;import com.yuanit.app.service.IPermissionService;import com.yuanit.app.util.AppConstants;import com.yuanit.sys.action.GenericAction;import com.yuanit.sys.util.EEMediaBeanFactory;public class LogInterceptor extends AbstractInterceptor Overridepublic String intercept(ActionInvocation invocation) throws Exception / TODO Auto-generated method stubString result = invocation.invoke();ActionContext ctx = invocation.getInvocationContext();Map session = ctx.getSession();Member member = (Member) session.get(AppConstants.LOGIN_MEMBER);Role role = (Role) session.get(AppConstants.LOGIN_ROLE);String url = /;StringBuffer urlStringBuffer = new StringBuffer(url);String actionName = invocation.getInvocationContext().getName(); String args = actionName.split(AppConstants.ACTION_SPLIT_CHAR);urlStringBuffer.append(actionName);urlStringBuffer.append(.action); if(args1.indexOf(AppConstants.ACTION_INDEXOF_DO) = 0) if(args1.indexOf(doEdit) = 0) GenericAction genericAction = (GenericAction)invocation.getAction(); int id = genericAction.getId(); if(id != 0) urlStringBuffer.append(?id=); url = urlStringBuffer.toString(); IPermissionService permissionService = EEMediaBeanFactory.getService(IPermissionService.class); /IMemberService memberService = EEMediaBeanFactory.getService(IMemberService.class); /IRoleService roleService = EEMediaBeanFactory.getService(IRoleService.class); Permission permission = permissionService.getPermission(url); ILogService logService = EEMediaBeanFactory.getService(ILogService.class); Log log = new Log(); if(permission != null) String operateDescription = permission.getPermissionDesc(); int operateRole = role.getId(); int operateMember = member.getId(); Long operateDate = new Date().getTime(); log.setOperateDate(operateDate); log.setOperateDescription(operateDescription); log.setOperateMember(operateMember); log.setOperateRole(operateRole); logService.createLog(log); return result;權(quán)限攔截器package erceptor;import java.util.Map;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import erceptor.AbstractInterceptor;import com.yuanit.app.dao.IRoleDAO;import com.yuanit.app.model.Permission;import com.yuanit.app.model.Role;import com.yuanit.app.service.IPermissionService;import com.yuanit.app.util.AppConstants;import com.yuanit.sys.util.EEMediaBeanFactory;public class PermissionValidateInterceptor extends AbstractInterceptor Overridepublic String intercept(ActionInvocation invocation) throws Exception ActionContext ctx = invocation.getInvocationContext();String actionName = invocation.getProxy().getActionName();if (AppConstants.ADMIN_GOLOGIN_ACTION.equals(actionName)| AppConstants.ADMIN_DOLOGIN_ACTION.equals(actionName)| AppConstants.ADMIN_GOINDEX_ACTION.equals(actionName)| AppConstants.ADMIN_GOLEFT_ACTION.equals(actionName)| AppConstants.PERMISSION_GETSUBPERMISSIONS_ACTION.equals(actionName) return invocation.invoke();String args = actionName.split(AppConstants.ACTION_SPLIT_CHAR);if (args1.indexOf(AppConstants.ACTION_INDEXOF_GO) = 0) Map session = ctx.getSession();Role role_login = (Role) session.get(AppConstants.LOGIN_ROLE);if (role_login = null) session.put(AppConstants.INTERCEPTOR_MESSAGE, 您還沒有登錄,請先登錄!);return Action.ERROR;IRoleDAO roleDAO = EEMediaBeanFactory.getService(IRoleDAO.class);Role role = roleDAO.findRole(role_login.getId();String role_permission = role.getRolePermissions();String url = /;StringBuffer urlStringBuffer = new StringBuffer(url);urlStringBuffer.append(actionName);urlStringBuffer.append(.action);url = urlStringBuffer.toString();IPermissionService permissionService = EEMediaBeanFactory.getService(IPermissionService.class);Permission permission = permissionService.getPermission(url);if (role_permission.contains(permission.getId().toString() return invocation.invoke(); else session.put(AppConstants.INTERCEPTOR_MESSAGE, 您沒有權(quán)限訪問此頁面!);return Action.ERROR; else return invocation.invoke();Struts中的配置!- - 日志攔截器的輔助調(diào)用方法一:package com.yuanit.sys.utilpublic static T getService(Class clz) if (ctx = null) throw new RuntimeException(application context wasnt intialized); String beanName = clz.getSimpleName(); if (beanName.startsWith(I) beanName = beanName.substring(1); beanName = beanName.substring(0, 1).toLowerCase() + beanName.substring(1); return (T)ctx.getBean(beanName);二:package com.yuanit.app.service.impl;/* * 根據(jù)權(quán)限URL取得權(quán)限信息 * param permissionURL 權(quán)限URL * return permission 權(quán)限對象 */Permission getPermission(String permissionURL) throws ServiceException;tryreturn permissionDAO.findPermission(permissionURL);catch(DAOException de)throw new ServiceException(de.getMessage();catch(Exception ex)logger.error(ex.getMessage();ex.printStackTrace();throw new ServiceException(根據(jù)權(quán)限URL取得權(quán)限信息發(fā)生錯誤.);權(quán)限攔截器的輔助方法一:package com.yuanit.sys.util; public static T getService(Class clz) if (ctx = null) throw new RuntimeException(application context wasnt intialized); String beanName = clz.getSimpleName(); if (beanName.startsWith(I) beanName = beanName.substring(1); beanName = beanName.substring(0, 1).toLowerCase() + beanName.substring(1); return (T)ctx.getBean(beanName);二:/* * 根據(jù)角色ID獲取權(quán)限對象 * param roleId * return * throws DAOException */public Role findRole(int roleId) throws DAOException tryreturn super.getObject(roleId);catch(DAOException ex)logger.error(取得 roleId( + roleId + ) 對應(yīng)的信息發(fā)生錯誤,該信息可能被刪除!);throw new DAOException(取得 roleId( + roleId + ) 對應(yīng)的信息發(fā)生錯誤,該信息可能被刪除!);catch(Exception exception)logger.error(取得 roleId( + roleId + ) 對應(yīng)的信息發(fā)生錯誤: + exception.getMessage();throw new DAOException(取得 roleId( + roleId + ) 對應(yīng)的信息發(fā)生錯誤!);其中APPConstantspackage com.yuanit.app.util;public class AppConstants public static int SUCCESS_YES = 1;/是否操作成功:是public static int SUCCESS_NO = 0;/是否操作成功:否public static String LOGIN_MEMBER = loginMember;/登錄用戶public static String LOGIN_ROLE = loginRole;/登錄角色public static int PAGINATION_RANGE = 10;/默認分頁大?。?0public static String RETURN_TYPE_JSON = json;/Action返回類型:Jsonpublic static St
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國北斗衛(wèi)星應(yīng)用行業(yè)營銷創(chuàng)新戰(zhàn)略制定與實施研究報告
- 2025-2030年中國汽車經(jīng)銷行業(yè)全國市場開拓戰(zhàn)略制定與實施研究報告
- 2025-2030年中國桑拿洗浴行業(yè)資本規(guī)劃與股權(quán)融資戰(zhàn)略制定與實施研究報告
- 2025-2030年中國控制線纜組件行業(yè)開拓第二增長曲線戰(zhàn)略制定與實施研究報告
- 自動噴水滅火系統(tǒng)的維護管理標準
- 拜師儀式主持詞
- 購置冬裝方式選擇的調(diào)查研究
- 家裝電梯知識培訓(xùn)課件
- 2024年一年級語文教學(xué)設(shè)計(合集篇)
- 廣東日化用品項目資金申請報告
- 2023年中國軟件行業(yè)基準數(shù)據(jù)SSM-BK-202310
- 天津市部分區(qū)2023-2024學(xué)年高一上學(xué)期期末練習(xí)生物試題【含答案解析】
- 稀土鋁合金電纜項目招商引資方案
- 人教版六年級數(shù)學(xué)下冊全冊分層作業(yè)設(shè)計含答案
- 面點專業(yè)職業(yè)生涯規(guī)劃與管理
- 紀梵希服裝營銷方案
- 農(nóng)耕研學(xué)基地可行性方案
- 《太陽能光伏技術(shù)》課件
- 2024年職業(yè)素養(yǎng)與商務(wù)禮儀培訓(xùn)資料
- 兒科課件:急性細菌性腦膜炎
- 柜類家具結(jié)構(gòu)設(shè)計課件
評論
0/150
提交評論