zoukankan      html  css  js  c++  java
  • spring security 表单认证的流程

    表单认证过程
    Spring security的表单认证过程是由org.springframework.security.web.authentication. UsernamePasswordAuthenticationFilter类中实现。而在spring security3.0之前是在AuthenticationProcessingFilter类中实现的。
    在UsernamePasswordAuthenticationFilter中的参数:
    public static final String SPRING_SECURITY_FORM_USERNAME_KEY = "j_username";//用户输入的用户名
        public static final String SPRING_SECURITY_FORM_PASSWORD_KEY = "j_password";//用户输入的密码
    public static final String SPRING_SECURITY_LAST_USERNAME_KEY = "SPRING_SECURITY_LAST_USERNAME";
    private boolean postOnly = true;//指定是不是由Post提交,而此类是不支持post提交的

    当过滤器链执行到UsernamePasswordAuthenticationFilter时会调用其父类AbstractAuthenticationProcessingFilter的doFilter方法。在这个方法中首先执行requiresAuthentication方法,判断此uri是不是j_spring_security_check,如果不是则判断不是认证操作,如果是则取得用户名和密码进行认证。AbstractAuthenticationProcessingFilter会调用UsernamePasswordAuthenticationFilter的attemptAuthentication方法进行验证,如果验证成功则放回一个经过认证的Authentication对象。

    进行认证时会取得提供管理ProvicerMnager,并执行其doAuthenticate方法,利用认证提供者类进行认证。
    第一个认证提供者类是:
    org.springframework.security.authentication.AnonymousAuthenticationProvider,此类不提供认证
    第二个认证提供者类是:
    org.springframework.security.authentication.dao.DaoAuthenticationProvider
    主要的认证操作是在DaoAuthenticationProvider中执行的。首先DaoAuthenticationProvider的父类执行authenticate方法。这个方法需要一个根据用户名获得的Authentication对象,authenticate方法首先在缓冲中判断有没有此用户,如果没有则执行DaoAuthenticationProvider的retrieveUser方法,这个方法通过配置文件中配置的UserDetails执行其loadUserByUsername返回一个UserDetails对象。之后在DaoAuthenticationProvider的additionalAuthenticationChecks方法对返回的UserDetails通过PlaintextPasswordEncoder类中的isPasswordValid方法进行验证。
    如果以上过程没有抛出异常,则为认证成功。 
  • 相关阅读:
    关于 RuntimeBinderException 异常
    IE 跨域session丢失问题
    一个简单的方法去掉angular application中URLs的hashtag
    ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
    (转载)Why you shouldn't use Entity Framework with Transactions
    angular自启动过程
    HTML中的IE条件注释,让低版本IE也能正常运行HTML5+CSS3网站的3种解决方案
    angualrjs 总结 随记(三)
    angualrjs 总结 随记(二)
    angualrjs 总结 随记(一)
  • 原文地址:https://www.cnblogs.com/lshan/p/8920788.html
Copyright © 2011-2022 走看看