添加dockerfile
This commit is contained in:
parent
2d48aeb8df
commit
5ec5842d4a
|
@ -5,6 +5,7 @@ import com.chint.domain.factoriy.user.UserFactory;
|
||||||
import com.chint.domain.repository.UserRepository;
|
import com.chint.domain.repository.UserRepository;
|
||||||
import com.chint.domain.value_object.UserLoginParam;
|
import com.chint.domain.value_object.UserLoginParam;
|
||||||
import com.chint.domain.value_object.UserLoginResult;
|
import com.chint.domain.value_object.UserLoginResult;
|
||||||
|
import com.chint.infrastructure.util.Digest;
|
||||||
import com.chint.infrastructure.util.JWTUtil;
|
import com.chint.infrastructure.util.JWTUtil;
|
||||||
import com.chint.infrastructure.util.Json;
|
import com.chint.infrastructure.util.Json;
|
||||||
import com.chint.infrastructure.util.Token;
|
import com.chint.infrastructure.util.Token;
|
||||||
|
@ -53,7 +54,8 @@ public class AuthenticateServiceImpl implements AuthenticateService {
|
||||||
claims.put(USER_LOGIN_PARAM, json.gson().toJson(userLoginParam));
|
claims.put(USER_LOGIN_PARAM, json.gson().toJson(userLoginParam));
|
||||||
String jwt = JWTUtil.createJWT(claims);
|
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 {
|
} else {
|
||||||
User newUser = userFactory.create(userLoginParam.getSfno());
|
User newUser = userFactory.create(userLoginParam.getSfno());
|
||||||
//如果数据库不存在该用户,需要通过sf信息进行查询并保存到数据库
|
//如果数据库不存在该用户,需要通过sf信息进行查询并保存到数据库
|
||||||
|
|
|
@ -2,10 +2,13 @@ package com.chint.domain.value_object;
|
||||||
|
|
||||||
import com.chint.domain.aggregates.user.User;
|
import com.chint.domain.aggregates.user.User;
|
||||||
import com.chint.infrastructure.util.Token;
|
import com.chint.infrastructure.util.Token;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class UserLoginResult {
|
public class UserLoginResult {
|
||||||
private User user;
|
private User user;
|
||||||
private Token token;
|
private Token token;
|
||||||
|
private String redirectUrl;
|
||||||
|
|
||||||
public UserLoginResult(User user) {
|
public UserLoginResult(User user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
@ -36,4 +39,9 @@ public class UserLoginResult {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserLoginResult redirectUrl(String url) {
|
||||||
|
this.redirectUrl = url;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -202,4 +202,8 @@ public class Constant {
|
||||||
public static final int CITY_TYPE_DOMESTIC = 0;//国内
|
public static final int CITY_TYPE_DOMESTIC = 0;//国内
|
||||||
public static final String CITY_TYPE_DOMESTIC_PATH = "3106_1_";//国内
|
public static final String CITY_TYPE_DOMESTIC_PATH = "3106_1_";//国内
|
||||||
public static final int CITY_TYPE_FOREIGN = 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";//国内
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
package com.chint.infrastructure.util;
|
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.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import static com.chint.infrastructure.constant.Constant.AES_SECRET;
|
||||||
|
|
||||||
public class Digest {
|
public class Digest {
|
||||||
|
|
||||||
|
@ -22,4 +31,44 @@ public class Digest {
|
||||||
throw new RuntimeException(e);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class RouteApplicationTests {
|
||||||
userHttpRequest.loadUserInfo(user);
|
userHttpRequest.loadUserInfo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
@Test
|
||||||
void loginSign() {
|
void loginSign() {
|
||||||
String sfno = "220322120";
|
String sfno = "220322120";
|
||||||
String syscode = "abc";
|
String syscode = "abc";
|
||||||
|
|
Loading…
Reference in New Issue