update 跨服务获取token
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
package com.jero.util;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.RestUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 跨服务调用时验证身份
|
||||
*/
|
||||
@Component
|
||||
public class AuthenticationUtils {
|
||||
|
||||
private static String URL;
|
||||
|
||||
private static String APPLICATION_TOKEN;
|
||||
|
||||
@Value("${standards.url}")
|
||||
public void setURL(String url) {
|
||||
AuthenticationUtils.URL = url;
|
||||
}
|
||||
@Value("${standards.token}")
|
||||
public void setApplicationToken(String applicationToken) {
|
||||
APPLICATION_TOKEN = applicationToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公钥并使用公钥加密token
|
||||
*/
|
||||
public static Map<String,String> encryptByRsaPriKey() {
|
||||
|
||||
Map<String,String> map= new HashMap<>();
|
||||
//从标协项目获取公钥
|
||||
String publicKey=HttpUtil.get(URL+"/sys/getStandardsRSAPublicKey");
|
||||
|
||||
RSA rsa = new RSA(null,publicKey);
|
||||
|
||||
byte[] token = rsa.encrypt(StrUtil.bytes(APPLICATION_TOKEN, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
String tokenStr = Base64.getEncoder().encodeToString(token);
|
||||
|
||||
map.put("publicKey",publicKey);
|
||||
map.put("token",tokenStr);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user