添加dockerfile

This commit is contained in:
lulz1 2024-02-18 14:28:17 +08:00
parent 2d48aeb8df
commit 5ec5842d4a
6 changed files with 66 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import com.chint.domain.factoriy.user.UserFactory;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.domain.value_object.UserLoginResult;
import com.chint.infrastructure.util.Digest;
import com.chint.infrastructure.util.JWTUtil;
import com.chint.infrastructure.util.Json;
import com.chint.infrastructure.util.Token;
@ -53,7 +54,8 @@ public class AuthenticateServiceImpl implements AuthenticateService {
claims.put(USER_LOGIN_PARAM, json.gson().toJson(userLoginParam));
String jwt = JWTUtil.createJWT(claims);
return UserLoginResult.buildWithUser(user).loadToken(Token.of(jwt));
return UserLoginResult.buildWithUser(user).loadToken(Token.of(jwt)).redirectUrl(SYSTEM_HOME_URL +
"?token=" + Digest.aes(jwt));
} else {
User newUser = userFactory.create(userLoginParam.getSfno());
//如果数据库不存在该用户需要通过sf信息进行查询并保存到数据库

View File

@ -2,10 +2,13 @@ package com.chint.domain.value_object;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.Token;
import lombok.Data;
@Data
public class UserLoginResult {
private User user;
private Token token;
private String redirectUrl;
public UserLoginResult(User user) {
this.user = user;
@ -36,4 +39,9 @@ public class UserLoginResult {
this.token = token;
return this;
}
public UserLoginResult redirectUrl(String url) {
this.redirectUrl = url;
return this;
}
}

View File

@ -202,4 +202,8 @@ public class Constant {
public static final int CITY_TYPE_DOMESTIC = 0;//国内
public static final String CITY_TYPE_DOMESTIC_PATH = "3106_1_";//国内
public static final int CITY_TYPE_FOREIGN = 1;//国外
//system
public static final String SYSTEM_HOME_URL = "www.baidu.com";//国内
public static final String AES_SECRET = "chint";//国内
}

View File

@ -1,7 +1,16 @@
package com.chint.infrastructure.util;
import javax.crypto.*;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import static com.chint.infrastructure.constant.Constant.AES_SECRET;
public class Digest {
@ -22,4 +31,44 @@ public class Digest {
throw new RuntimeException(e);
}
}
private static final SecretKey secretKey = generateKey(128); // 类级别的密钥
// 生成密钥
private static SecretKey generateKey(int n) {
try {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(n); // 可以是 128, 192, 256
return keyGenerator.generateKey();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String aes(String input) {
try {
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(input.getBytes());
String encodedEncryptedToken = Base64.getEncoder().encodeToString(encryptedBytes);
return URLEncoder.encode(encodedEncryptedToken, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String aesBack(String input) {
try {
String urlDecodedToken = URLDecoder.decode(input, StandardCharsets.UTF_8);
byte[] encryptedBytes = Base64.getDecoder().decode(urlDecodedToken);
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
return new String(decryptedBytes);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -42,7 +42,7 @@ public class SignUtils {
for (int i = 0; i < bytes.length; i++) {
temp = Integer.toHexString(bytes[i] & 0xFF);
if (temp.length() == 1) {
//1得到一位的进行补0操作
//1得到一位的进行补0操作
stringBuffer.append("0");
}
stringBuffer.append(temp);

View File

@ -29,7 +29,7 @@ class RouteApplicationTests {
userHttpRequest.loadUserInfo(user);
}
//@Test
@Test
void loginSign() {
String sfno = "220322120";
String syscode = "abc";