移除鉴权
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package cn.van.business.service;
|
||||
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import cn.van.business.model.user.AdminUser;
|
||||
import cn.van.business.util.Util;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class AdminUserService {
|
||||
|
||||
|
||||
// 模拟数据库存储
|
||||
private static final Map<String, AdminUser> users = new HashMap<>();
|
||||
|
||||
static {
|
||||
// 初始化一个测试用户(生产环境应从数据库加载)
|
||||
AdminUser user = new AdminUser();
|
||||
user.setUsername("van");
|
||||
String password = Util.md5("LK.807878712");
|
||||
user.setPassword(new BCryptPasswordEncoder().encode(password));
|
||||
users.put("van", user);
|
||||
}
|
||||
|
||||
public AdminUser findByUsername(String username) {
|
||||
return users.get(username);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package cn.van.business.service;
|
||||
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
@Service
|
||||
public class CaptchaService {
|
||||
|
||||
private final Producer kaptchaProducer;
|
||||
|
||||
public CaptchaService(Producer kaptchaProducer) {
|
||||
this.kaptchaProducer = kaptchaProducer;
|
||||
}
|
||||
|
||||
public String generateCaptchaImage() throws Exception {
|
||||
String text = kaptchaProducer.createText();
|
||||
BufferedImage image = kaptchaProducer.createImage(text);
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "PNG", outputStream);
|
||||
return Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||
}
|
||||
|
||||
public boolean validateCaptcha(String userInput, String generatedCaptcha) {
|
||||
return userInput.equalsIgnoreCase("Succ");
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package cn.van.business.service.impl;
|
||||
|
||||
import cn.van.business.model.user.AdminUser;
|
||||
import cn.van.business.service.AdminUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
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.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@Service
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
AdminUser user = adminUserService.findByUsername(username);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException("用户不存在");
|
||||
}
|
||||
|
||||
return User.builder()
|
||||
.username(user.getUsername())
|
||||
.password(user.getPassword())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user