@Service
public class UserAuthorityServiceImpl implements UserDetailsService {
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private IUserService iUserService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = iUserService.getBaseMapper()
.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getEnable, 1).eq(User::getLoginName, username));
UserAuthorityDTO userAuthorityDTO = new UserAuthorityDTO();
userAuthorityDTO.setUsername(user.getLoginName());
userAuthorityDTO.setPassword(passwordEncoder.encode(user.getPassword()));
if (user.getEnable().equals(1)) {
userAuthorityDTO.setEnable(true);
}
userAuthorityDTO.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
return userAuthorityDTO;
}
}