spring security3.x学习(24)_拒绝访问异常处理(AccessDeniedException)
来源:互联网 发布:阿里云服务器创建快照 编辑:程序博客网 时间:2024/05/21 06:40
咱们看一下spring security是如何处理AccessDeniedException的。
“
因为缺少GrantedAuthority或其它需要的权限被拒绝的时候,他们看到的是servlet容器的默认HTTP 403(访问拒绝)页面。这 个 页 面 是 o.s.s.web.access.AccessDeniedHandler 默 认 行 为 的 结 果 , 它 被ExceptionTranslationFilter所触发以响应框架抛出的一个AccessDeniedException异常。
”
我看了书中的例子,书中的例子导入后,会报错的,所以我自己写了一个。
首先在http标签下配置一个AccessDenied指向路径:
<!-- 拒绝请求的处理 --><access-denied-handler error-page="/accessDenied.html"/>
然后配置controller:
@Controllerpublic class ErrorController {@RequestMapping("/accessDenied")public String accessDenied(ModelMap mm,HttpServletRequest request){Object obj = request.getAttribute("SPRING_SECURITY_403_EXCEPTION");if(null != obj){AccessDeniedException adx = (AccessDeniedException)obj;mm.put("errorDetails", adx.getMessage());}return "error/403";}}
我说的报错就是这里,我们通过request.getAttribute("SPRING_SECURITY_403_EXCEPTION");可以获取AccessDeniedException对象,从而拿到错误信息了。那我是怎么知道这个常量的名字叫做"SPRING_SECURITY_403_EXCEPTION"呢?
看一下源码就知道了:
源码中存放了AccessDeniedException对象,我们可以获取他,在我们自己的Controller中。最后我们要完成我们自己的jsp页面。
只有一句话(EL表达式):错误信息:${errorDetails}
我们在研究一下什么会触发这类异常呢,看一下下边的表:
这样我们就知道了,其实AccessDeniedException是在没有权限时,被拒绝访问了。我想 大概就是403错误码吧。
下载地址:http://download.csdn.net/detail/dulei294948/6307619
- spring security3.x学习(24)_拒绝访问异常处理(AccessDeniedException)
- spring security3.x学习(24)_拒绝访问异常处理(AccessDeniedException)
- spring security3.x学习(7)_访问决策管理
- spring security3.x学习(7)_访问决策管理
- spring security3.x学习(11)_退出
- spring security3.x学习(11)_退出
- spring security3.x学习(6)_认证详细流程和认证异常
- spring security3.x学习(6)_认证详细流程和认证异常
- spring security3.x学习(1)_必备资料&开始学习
- spring security3.x学习(4)_认证管理的过程
- spring security3.x学习(5)_如何拦截用户请求
- spring security3.x学习(10)_自定义的登录页面
- spring security3.x学习(15)_扩展JdbcDaoImpl。
- spring security3.x学习(21)_关于方法过滤
- spring security3.x学习(22)_关于ip的过滤器
- spring security3.x学习(3)_初探过滤器机制
- spring security3.x学习(4)_认证管理的过程
- spring security3.x学习(5)_如何拦截用户请求
- yuv420p
- poj 4756 Install Air Conditioning 生成树变形
- linux红黑树解读
- php生成静态html
- 基于ADCensus视差的多视点转换
- spring security3.x学习(24)_拒绝访问异常处理(AccessDeniedException)
- php身份证验证类
- yum安装PHP的安装memcache扩展全攻略
- Xcode4.6 自制iOS可用的 Framework
- php简单验证码类(字母+数字)
- PHP explode() 函数源码分析
- JVM学习之两种异常StackOverflowError和OutOfMemoryError产生的原因
- tomcat报内存溢出 java.lang.OutOfMemoryError: PermGen space
- 分页加载数据