表单认证过程 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方法进行验证。 若是以上过程没有抛出异常,则为认证成功。