merge
This commit is contained in:
@@ -19,10 +19,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 说明: 用户服务层
|
||||
@@ -302,7 +299,9 @@ public class SysUserService {
|
||||
throw new BusinessException("保存用户登录日志失败");
|
||||
}
|
||||
//保存登录数据
|
||||
String token = RSAUtil.decrypt(userName + ip);
|
||||
String token = RSAUtil.encrypt(userName + "_" + ip);
|
||||
//对有换行的token编码
|
||||
token = EncodeUtils.urlEncode(token);
|
||||
CommonDataUtil.setToken(token, userName);
|
||||
restMessage.setData(token);
|
||||
restMessage.setSuccess(true);
|
||||
|
||||
@@ -13,6 +13,8 @@ import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -230,21 +232,23 @@ public class RSAUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String en = testJiami();// 密文
|
||||
String de = testJiemi(en);// 明文
|
||||
System.out.println(de);
|
||||
}
|
||||
|
||||
private static String testJiami() {
|
||||
String plainText = encrypt(loadPublicKey(), "123456");
|
||||
private static String testJiami() throws Exception {
|
||||
String plainText = encrypt(loadPublicKey(), "123456");//加密后的密文有换行
|
||||
System.out.println("加密结果:" + plainText);
|
||||
System.out.println("加密结果encode:" + URLEncoder.encode(plainText, "utf-8"));
|
||||
return plainText;
|
||||
}
|
||||
|
||||
private static String testJiemi(String str) {
|
||||
private static String testJiemi(String str) throws Exception {
|
||||
String plainText = decrypt(loadPrivateKey(), str);
|
||||
System.out.println("解密结果:" + plainText);
|
||||
System.out.println("加密结果encode:" + URLDecoder.decode(plainText, "utf-8"));
|
||||
return plainText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public class CaptchaServlet extends HttpServlet {
|
||||
StringBuffer code = new StringBuffer();
|
||||
BufferedImage image = tool.genRandomCodeImage(code);
|
||||
HttpSession session = req.getSession();
|
||||
session.setMaxInactiveInterval(60 * 60);//单位为秒,-1永不过期
|
||||
session.setAttribute(CommonConstant.KEY_CAPTCHA, code.toString());
|
||||
// CommonDataUtil.setToken(CommonConstant.KEY_CAPTCHA, code.toString());
|
||||
// 将内存中的图片通过流形式输出到客户端
|
||||
|
||||
@@ -28,19 +28,15 @@ import java.util.List;
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
public Docket sysDocket() {
|
||||
ParameterBuilder ticketPar = new ParameterBuilder();
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
ticketPar.name("token").description("令牌")
|
||||
.modelRef(new ModelRef("string")).parameterType("header")
|
||||
.required(false).build(); //header中的ticket参数非必填,传空也可以
|
||||
pars.add(ticketPar.build());
|
||||
List<Parameter> pars = addParams();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("system")
|
||||
.apiInfo(sysApiInf())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.xwbing.controller.sys"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
.build()
|
||||
.globalOperationParameters(pars);
|
||||
}
|
||||
|
||||
private ApiInfo sysApiInf() {
|
||||
@@ -55,19 +51,15 @@ public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket otherDocket() {
|
||||
ParameterBuilder ticketPar = new ParameterBuilder();
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
ticketPar.name("token").description("令牌")
|
||||
.modelRef(new ModelRef("string")).parameterType("header")
|
||||
.required(false).build(); //header中的ticket参数非必填,传空也可以
|
||||
pars.add(ticketPar.build());
|
||||
List<Parameter> pars = addParams();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("other")
|
||||
.apiInfo(otherApiInf())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.xwbing.controller.other"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
.build()
|
||||
.globalOperationParameters(pars);
|
||||
}
|
||||
|
||||
private ApiInfo otherApiInf() {
|
||||
@@ -79,4 +71,19 @@ public class SwaggerConfig {
|
||||
.version("1.0.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<Parameter> addParams() {
|
||||
ParameterBuilder ticketPar = new ParameterBuilder();
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
ticketPar.name("token").description("令牌")
|
||||
.modelRef(new ModelRef("string")).parameterType("header")
|
||||
.required(false).build();
|
||||
pars.add(ticketPar.build());
|
||||
return pars;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user