Merge remote-tracking branch 'origin/guoshengxiong' into guoshengxiong

This commit is contained in:
Administrator 2023-03-31 09:06:09 +08:00
commit da9f8edd12
4 changed files with 63 additions and 7 deletions

View File

@ -123,7 +123,7 @@ public class SjMqService {
public void onUserOrgChanged(UserOrgChangeMessage userOrgChangeMessage) {
/*
新增用户
复制用户
{
"category": "2-2",
"id": "wnibicyw0TTVSymhmKmWW1ZA",
@ -207,8 +207,36 @@ public class SjMqService {
"type": "DELETE"
}
*/
/*
新增用户
{
"category": "2-2",
"id": "9JLOEdkVTZaiaRYtNsTgkIg",
"orgId": "u0D9zibI1TjKUCVjub94DiaA",
"timestamp": 1680184324373,
"type": "ADD",
"user": {
"creator": "Z4K0Un08TibykTF5tiauD15Q",
"sex": "1",
"jobs": "",
"avatar": "",
"categoryUsers": [],
"workno": "",
"phone": "1915895123122333333333333",
"name": "测试用户222",
"state": "1",
"sn": 0,
"id": "9JLOEdkVTZaiaRYtNsTgkIg",
"certificateNum": "540102197511234444",
"authLevel": "0",
"email": "",
"effectiveDate": 0,
"certificateType": "idcard"
}
}
*/
UserOrgChangeType type = userOrgChangeMessage.getType();
if (type.equals(UserOrgChangeType.COPY)) {
if (type.equals(UserOrgChangeType.COPY) || type.equals(UserOrgChangeType.ADD)) {
//复制 新增用户
SystemUser systemUser = convertToSystemUser(userOrgChangeMessage);
systemUserMapper.insert(systemUser);

View File

@ -93,7 +93,7 @@ public class SjLoginController {
*/
@GetMapping("getLoginInfoByToken")
@ResponseBody
public Result getLoginInfoByToken(@RequestParam String uid) throws InvalidKeySpecException {
public Result getLoginInfoByToken(@RequestParam String uid) throws InvalidKeySpecException, IOException {
log.info("uid>>>{}", uid);
JwtPayloadUserInfo jwtPayloadUserInfo = JwtRsaUtils.verifyWithUserInfo(uid);
if (jwtPayloadUserInfo != null) {

View File

@ -1,7 +1,6 @@
package com.zhgd.xmgl.util.sj;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
@ -14,7 +13,12 @@ import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import com.zhgd.xmgl.entity.sj.JwtPayloadUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.StreamUtils;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
@ -226,8 +230,9 @@ public class JwtRsaUtils {
*
* @throws InvalidKeySpecException
*/
public static JwtPayloadUserInfo verifyWithUserInfo(String token) throws InvalidKeySpecException {
String publicKey = FileUtil.readString(Thread.currentThread().getContextClassLoader().getResource("sj/auth_public_key.pem").getPath(), "UTF-8");
public static JwtPayloadUserInfo verifyWithUserInfo(String token) throws InvalidKeySpecException, IOException {
String publicKey = readClassPathString("sj/auth_public_key.pem");
RSAKey rsaKey = JwtRsaUtils.getRsaKey("", publicKey);
// 验证并返回payload
@ -235,4 +240,26 @@ public class JwtRsaUtils {
JwtPayloadUserInfo jwtPayloadUserInfo = JSON.parseObject(jwt.getPayload().toString(), JwtPayloadUserInfo.class);
return jwtPayloadUserInfo;
}
public static String readClassPathString(String path) {
ClassPathResource classPathResource = new ClassPathResource("sj/auth_public_key.pem");
InputStream inputStream = null;
String s = null;
try {
inputStream = classPathResource.getInputStream();
s = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
} catch (IOException e) {
log.error("err", e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log.error("err", e);
}
}
}
return s;
}
}

View File

@ -2,10 +2,11 @@ package com.zhgd.xmgl.util.sj;
import com.zhgd.xmgl.entity.sj.JwtPayloadUserInfo;
import java.io.IOException;
import java.security.spec.InvalidKeySpecException;
public class JwtTest {
public static void main(String[] args) throws InvalidKeySpecException {
public static void main(String[] args) throws InvalidKeySpecException, IOException {
//String publicKey = "-----BEGIN PUBLIC KEY-----\n" +
// "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCufiaX7LnqAL9YNax00Gi9L/Zq\n" +
// "W4syUa5c0G9aJiwKc7YD2oljH78fSO+zekmKGLm3LRHvEEKooYlabispSMc0iNOt\n" +