码迷,mamicode.com
首页 > 编程语言 > 详细

spring-security中的entry-point-ref属性

时间:2014-12-04 12:24:22      阅读:468      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   使用   sp   for   on   

entry-point-ref属性,英文的意思是入口点引用。为什么需要这个入口点呢。这个入口点其实仅仅是被ExceptionTranslationFilter引用的。前面已经介绍过ExceptionTranslationFilter过滤器的作用是异常翻译,在出现认证异常、访问异常时,通过入口点决定redirect、forward的操作。比如现在是form-login的认证方式,如果没有通过UsernamePasswordAuthenticationFilter的认证就直接访问某个被保护的url,那么经过ExceptionTranslationFilter过滤器处理后,先捕获到访问拒绝异常,并把跳转动作交给入口点来处理。form-login的对应入口点类为LoginUrlAuthenticationEntryPoint,这个入口点类的commence方法会redirect或forward到指定的url(form-login标签的login-page属性) 

我使用的是restfull风格,所以entry-point-ref所参照的类如下

public class UnauthorizedEntryPoint implements AuthenticationEntryPoint
{
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,         AuthenticationException authException)
            throws IOException, ServletException
        {
            response.sendError(
                HttpServletResponse.SC_UNAUTHORIZED,
                "Unauthorized: Authentication token was either missing or invalid.");
        }
}


spring-security中的entry-point-ref属性

标签:style   http   io   ar   color   使用   sp   for   on   

原文地址:http://my.oschina.net/bigyuan/blog/352099

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!