若依登录自定义扩展Springboot+security支持密码、手机验证码登录方式

本文介绍如何在若依框架基础上扩展Springboot Security,实现手机号+密码及手机号+短信验证码的登录认证。通过继承DaoAuthenticationProvider,重写additionalAuthenticationChecks方法,根据密码标识区分不同验证方式,并在SecurityConfig中配置自定义的authenticationProvider。同时,提供了登录接口的实现和用户验证逻辑。
摘要由CSDN通过智能技术生成

若依开源框架登录使用的配置大部分都是security自定义的,目前希望在此框架基础上支持自定义的登录,如手机号+密码登录认证、手机号+短信验证码认证。
1、自定义登录实现思路

主要是实现继承DaoAuthenticationProvider类,重写additionalAuthenticationChecks方法,将通过密码标识来判断是不是需要验证密码和免密验证。

2、继承DaoAuthenticationProvider

`import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**

  • 短信登陆鉴权 Provider,要求实现 AuthenticationProvider 接口
    */
    public class SmsCodeAuthenticationProvider extends DaoAut

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值