- 0
- 0
- 约7.56千字
- 约 6页
- 2016-11-27 发布于重庆
- 举报
基于springaop權限管理系统原型
基于spring aop 权限管理系统原型
此权限管理系统把待访问的业务层方法做为权限管理中的资源,通过spring aop 对接口方法进行拦截,来实现权限的管理,可以实现细粒度的权限控制。在上文体验了spring aop 一些特性,aop 接口:MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice 实现这三个接口分别对方法执行前,后,执行中抛异常等情况进行的,我们要是想做overload 这样的操作时,要用MethodInterceptor 接口,此接口好在有返回值,public Object invoke(??????MethodInvocation invocation) ??????throws Throwable?? {//.}上文做法有些牵强业务逻辑还有throws PermissionDeniedException 感觉不爽,现在用MethodInterceptor 接口,来写这个demo,把权限与业务分开。advice 如下:public class PermissionCheckAroundAdvice implements MethodInterceptor {????SecurityManager securityMgr = new SecurityManager();????????/**//**???? * @param securityMgr The securityMgr to set.???? */????public void setSecurityMgr(SecurityManager securityMgr) {????????this.securityMgr = securityMgr;????}????public Object invoke(MethodInvocation invocation) throws Throwable {????????System.out.println((被调用方法接口类名: ????????????????+ invocation.getMethod().getDeclaringClass().getName() + ));????????System.out.println((被调用方法名: + invocation.getMethod().getName()+ ));????????String methodName = invocation.getMethod().getDeclaringClass()????????????????.getName() + . + invocation.getMethod().getName();????????System.out.println((被调用方法全名: + methodName + ));????????System.out.println(有否权限:( + securityMgr.checkPermission(methodName)+ ));????????if(securityMgr.checkPermission(methodName))????????????return ceed();???????? System.out.println(Goodbye! NO Permission!(by + this.getClass().getName() + ));????????return --;????}}服务层业务接口修改如下:public interface Service {????public String getBeanInfo();}服务层业务实现类如下:public class ServiceBean implements Service {????ResourceBean bean;????/**//**???? * @param bean The bean to set.???? */????public void setBean(ResourceBean bean) {????????this.bean = bean;????}????public String getBeanInfo(){????????String result=;????????????????result+= bean.getMethod1();????????result+= bean.getMethod2();????????result+= bean.getMethod3();????????return resu
您可能关注的文档
最近下载
- 陕西省安康市清北班2025届高三4月联考模拟预测语文试题(含答案与解析).pdf VIP
- 厨房电器行业电商渠道在2025年拓展的市场竞争分析与策略.docx
- 李春丽--八年级年级主任工作总结.pptx VIP
- ISO22716-GMPC一整套文件汇编(手册、程序文件、管理制度及对应的表单).doc VIP
- 肺栓塞应急预案培训与演练脚本.doc VIP
- 2023年厦门市同安区事业单位真题及答案.docx VIP
- 高中语文选择性必修下册全册教案.docx VIP
- 西师大版小学四年级下册数学全册课件(2024年2月修订).pptx
- 08-高速铁路设计要求规范条文(8隧道).pdf VIP
- 2026年军队文职考试《公共科目》真题.pdf VIP
原创力文档

文档评论(0)