|
|
@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
@ -56,8 +57,8 @@ public class DecryptThirdTokenFilter extends OncePerRequestFilter { |
|
|
|
private final Gson gson = new Gson(); |
|
|
|
// 新增加密服务实例(在类顶部) |
|
|
|
private final SMCryptoService smCryptoService = new SMCryptoServiceImpl(); |
|
|
|
private static final String encrypt_key_bjiemi = "8iot1blDJgNK36Do"; // 部解密省加密 |
|
|
|
private static final String encrypt_key_bjiami = "QLdQIASYMlT9SUUg"; //部加密省解密 |
|
|
|
private static final String encrypt_key = "8iot1blDJgNK36Do"; // 部解密省加密 |
|
|
|
private static final String decrypt_key = "QLdQIASYMlT9SUUg"; //部加密省解密 |
|
|
|
private static final BytesKeyGenerator DEFAULT_TOKEN_GENERATOR = KeyGenerators.secureRandom(20); |
|
|
|
private static final Charset US_ASCII = Charset.forName("US-ASCII"); |
|
|
|
@Autowired |
|
|
@ -192,7 +193,8 @@ public class DecryptThirdTokenFilter extends OncePerRequestFilter { |
|
|
|
} else { |
|
|
|
String sourceType = "data_exchange_client"; |
|
|
|
String tokenValue = new String(Base64.encodeBase64URLSafe(DEFAULT_TOKEN_GENERATOR.generateKey()), US_ASCII); |
|
|
|
tokenMap.put("token",sourceType + "_" + tokenValue); |
|
|
|
String tokenValueBase64 = Base64.encodeBase64String((sourceType + "_" + tokenValue).getBytes(StandardCharsets.UTF_8)); |
|
|
|
tokenMap.put("token", encryptBody(tokenValueBase64)); |
|
|
|
String tokenBody = gson.toJson(tokenMap); |
|
|
|
String crc = calculateSM3(tokenBody); |
|
|
|
String responseBody = encryptBody(tokenBody); |
|
|
@ -201,7 +203,7 @@ public class DecryptThirdTokenFilter extends OncePerRequestFilter { |
|
|
|
transportRequest.getHeader().setCrc(crc); |
|
|
|
transportRequest.setBody(responseBody); |
|
|
|
OauthClientDetails client = this.oauthClientDetailsService.findById(user); |
|
|
|
client.setAccessTokenInfo(responseBody); |
|
|
|
client.setAccessTokenInfo(encryptBody(tokenValueBase64)); |
|
|
|
oauthClientDetailsService.updateOauthClientDetails(client); |
|
|
|
} |
|
|
|
|
|
|
@ -252,7 +254,7 @@ public class DecryptThirdTokenFilter extends OncePerRequestFilter { |
|
|
|
// SM4加密Body(ECB模式) |
|
|
|
public String encryptBody(String plainText) throws Exception { |
|
|
|
EncryptCodeBean encryptCodeBean = new EncryptCodeBean(); |
|
|
|
encryptCodeBean.setSecretKey(encrypt_key_bjiami); |
|
|
|
encryptCodeBean.setSecretKey(encrypt_key); |
|
|
|
encryptCodeBean.setPass(plainText); |
|
|
|
String cipherText = smCryptoService.encrypt_Body(encryptCodeBean); |
|
|
|
return cipherText; |
|
|
@ -260,7 +262,7 @@ public class DecryptThirdTokenFilter extends OncePerRequestFilter { |
|
|
|
// SM4解密Body(ECB模式) |
|
|
|
public String decryptBody(String plainText) throws Exception { |
|
|
|
DecryptCodeBean encrypt2 = new DecryptCodeBean(); |
|
|
|
encrypt2.setSecretKey(encrypt_key_bjiami); |
|
|
|
encrypt2.setSecretKey(decrypt_key); |
|
|
|
encrypt2.setPass(plainText); |
|
|
|
String cipherText = smCryptoService.decrypt_Body(encrypt2); |
|
|
|
return cipherText; |
|
|
|