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方法进行验证。
如果以上过程没有抛出异常,则为认证成功。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zm274310577

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值