欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringSecurity---实现图形验证码的AuthenticationProvider

程序员文章站 2024-03-19 14:57:52
...
package com.zcw.demospringsecurity.demo7;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.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.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @ClassName : MyAuthenticationProvider
 * @Description : 校验图形验证码
 * @Author : Zhaocunwei
 * @Date: 2020-04-10 23:31
 */
@Component
public class MyAuthenticationProvider extends DaoAuthenticationProvider {

    public MyAuthenticationProvider(UserDetailsService userDetailsService,
                                    PasswordEncoder passwordEncoder){
        this.setUserDetailsService(userDetailsService);
        this.setPasswordEncoder(passwordEncoder);
    }
    @Override
    protected void additionalAuthenticationChecks(UserDetails userDetails,
                                                  UsernamePasswordAuthenticationToken  usernamePasswordAuthenticationToken)
        throws AuthenticationException {
        //调用父类方法完成密码验证
        super.additionalAuthenticationChecks(userDetails,usernamePasswordAuthenticationToken);
    }
}

相关标签: 安全框架