mirror of
https://github.com/RemainderTime/spring-boot-base-demo.git
synced 2026-02-21 14:30:56 +08:00
登录页面
登录接口功能
This commit is contained in:
@@ -157,25 +157,29 @@ public class RSAUtils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Map<String, String> encryptKey = createEncryptKey();
|
||||
String publicKey = encryptKey.get("publicKey");
|
||||
String privateKey = encryptKey.get("privateKey");
|
||||
|
||||
System.out.println("公匙加密串:" + publicKey);
|
||||
System.out.println("私匙加密串:" + privateKey);
|
||||
|
||||
// Map<String, String> encryptKey = createEncryptKey();
|
||||
// String publicKey = encryptKey.get("publicKey");
|
||||
// String privateKey = encryptKey.get("privateKey");
|
||||
//
|
||||
// System.out.println("公匙加密串:" + publicKey);
|
||||
// System.out.println("私匙加密串:" + privateKey);
|
||||
//
|
||||
// System.out.println();
|
||||
//
|
||||
// String data = "哈哈哈哈哈哈哈";
|
||||
// //加密
|
||||
// try {
|
||||
//加密
|
||||
try {
|
||||
// String s = publicEncrypt(data, getPublicKey(publicKey));
|
||||
// System.out.println("加密后密文:" + s);
|
||||
//
|
||||
// String s1 = privateDecryption(s, getPrivateKey(privateKey));
|
||||
// System.out.println("解密后明文:" + s1);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// throw new IllegalArgumentException();
|
||||
// }
|
||||
|
||||
String ss = "bPrP3VQpVNj7jxzSvVRQQpOCzg4c9HAMd/Sesda0SOxmWbNzP8SnhayV2H9Jpih2sf26O8dOqiNE7V1u5NPgQBIPi6LqX2QiFTjynVLxQBUmISfmQ2Q6K3sjHBIRIhuZPrXijw7CextUUQwzh4VvEVkjyaUnqlMXVRkUGlgqP7M=";
|
||||
String privateKey1 = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALiJJ6RPMMh-ETrmppOG7JKINPSFaaZoHjzZkyQl3AcfrpKMmH82j_Pxl4mPvvgKtbR20N-88-nJLT4v4aOz9XYVl5ruE59SsJl_T8YqN-i8L8KH8Wptd0_ee7nDhF4-OGEi-o330daFv20eLpboy6nDkWLmLihKC0jEZWK8MLZzAgMBAAECgYAEhO9gmcPjFRtM6vsnX8WJbSaG2oGU3rXm3Zk56Gd0ETWQRzsw2mA6JC-G4etWXcTHb6V75T-_-PpPrJKFFNItEH-WFRS36xneomycxRG1YTfK1SsGLGF0BV3bLVZx8cQz7VsBY4vqbRCSKtcOZBJpnxI6iHAv07i8w34F6qjfsQJBAORnKUuJQ_GsHHBPT1VhMYjXVepAfTrWtCzRQ648KavbHLAGaRIhX10uj-hAhZLafDqQF8Y7T7GHTlasRL9ubWsCQQDO1R3KScJJSR3KDsnSsF0YCw7V28cr_OVAwiPoro90Me6MUz9yKV88gQlTuJkNFMuu_YdPXYKjlzNVg0zFmtUZAkEAoe9mPtDeZD0TmKkSZUVYul1543C_mPTan5_qrWCoZtkd2MtiuWEB3O4DR7ZfPcQ8KcU5pektUn_NEfRndZYUawJBAJfydOoxeawBLQNODfLcYefR59owlYe5SGpktaCw7O596DPqzId_4Vk_qqx4xueXSXOLCabCmcC4yZue0_2vm7ECQQDLrzXL-BpSqxbvtE0gNKcgaSkEUSOh1QmQFPCHERsOBxcflM6ej71STKglB21JD9m6tM2RySgbtUx4TfOuJTek";
|
||||
String s1 = privateDecryption(ss, getPrivateKey(privateKey1));
|
||||
System.out.println("解密后明文:" + s1);
|
||||
|
||||
}catch (Exception e){
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
34
src/main/java/cn/xf/basedemo/controller/UserController.java
Normal file
34
src/main/java/cn/xf/basedemo/controller/UserController.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package cn.xf.basedemo.controller;
|
||||
|
||||
import cn.xf.basedemo.service.UserService;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @program: xf-boot-base
|
||||
* @ClassName UserController
|
||||
* @description:
|
||||
* @author: xiongfeng
|
||||
* @create: 2022-06-28 09:17
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@ApiOperation(value = "用户登录", notes = "用户登录")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@PostMapping("/login")
|
||||
public String login(@RequestBody String encryptedData){
|
||||
|
||||
return userService.login(encryptedData);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class TokenInterceptor implements HandlerInterceptor {
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
//不拦截的请求列表
|
||||
private static final List<String> EXCLUDE_PATH_LIST = Arrays.asList("");
|
||||
private static final List<String> EXCLUDE_PATH_LIST = Arrays.asList("/user/login");
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
13
src/main/java/cn/xf/basedemo/service/UserService.java
Normal file
13
src/main/java/cn/xf/basedemo/service/UserService.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package cn.xf.basedemo.service;
|
||||
|
||||
/**
|
||||
* @program: xf-boot-base
|
||||
* @ClassName UserService
|
||||
* @description:
|
||||
* @author: xiongfeng
|
||||
* @create: 2022-06-28 09:21
|
||||
**/
|
||||
public interface UserService {
|
||||
|
||||
String login(String encryptedData);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.xf.basedemo.service.impl;
|
||||
|
||||
import cn.xf.basedemo.common.utils.RSAUtils;
|
||||
import cn.xf.basedemo.config.GlobalConfig;
|
||||
import cn.xf.basedemo.service.UserService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @program: xf-boot-base
|
||||
* @ClassName UserServiceImpl
|
||||
* @description:
|
||||
* @author: xiongfeng
|
||||
* @create: 2022-06-28 09:21
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private GlobalConfig globalConfig;
|
||||
|
||||
@Override
|
||||
public String login(String encryptedData) {
|
||||
|
||||
if(StringUtils.isEmpty(encryptedData)){
|
||||
return null;
|
||||
}
|
||||
|
||||
String loginJson = "";
|
||||
try {
|
||||
loginJson = RSAUtils.privateDecryption(encryptedData, RSAUtils.getPrivateKey(globalConfig.getRsaPrivateKey()));
|
||||
}catch (Exception e){
|
||||
log.error("解密失败------》》》");
|
||||
}
|
||||
log.error("解密数据----" + loginJson);
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user