cloud-manage-new/src/main/java/cn/com/taiji/manage/config/security/AuthenticationProviderImpl.java

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package cn.com.taiji.manage.config.security;

import cn.com.taiji.manage.dto.user.UserListDto;
import cn.com.taiji.manage.service.UserService;
import cn.com.taiji.manage.service.impl.MyUserDetailService;
import cn.com.taiji.manage.util.EmptyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class AuthenticationProviderImpl implements AuthenticationProvider {
    @Autowired
    private UserService userService;
    @Autowired
    private MyUserDetailService myUserDetailService;


    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        String username=authentication.getName();
        String password=authentication.getCredentials().toString();
        //username
        System.out.println("user name: "+authentication.getName());
        //password
        System.out.println("password: "+authentication.getCredentials());
        System.out.println("getPrincipal: "+authentication.getPrincipal());
        System.out.println("getAuthorities: "+authentication.getAuthorities());
        System.out.println("getDetails: "+authentication.getDetails());
        UserListDto member = userService.getUserInfoByUserName(username);
        if(EmptyUtil.isEmpty(member))
        {
            throw new BadCredentialsException("该帐号不存在!");
        }
        else {
            if (member.getStatus().equals("0")) {
                throw new BadCredentialsException("该帐号已锁定,请您联系管理员!");
            }
            else if (!password.equals(member.getLoginPassword())) {
                if(member.getStatus().equals("1")) {
                    // 用户失败次数
                    int fails = member.getLoginCnt();
                    fails++;
                    // 系统配置失败次数
                    int FAILS_COUNT = 5;
                    // 超出失败次数,停用账户
                    if (fails >= FAILS_COUNT) {
                        userService.updateStatusById(member.getId(), "0");
                    } else {
                        // 失败次数++
                        userService.updateErrorLoginCnt(member.getId());
后面还有 47 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。