CustomUserDetailService.java
1.1 KB
package com.tianbo.warehouse.security;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service("customuserservice")
public class CustomUserDetailService implements UserDetailsService {
@Autowired
UserService userService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
USERS user = userService.loadByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("用户名不存在");
// throw new BadCredentialsException("用户名不存在");
}
return user;
}
}