1.用能代码提交

2.系统并发bug修改
This commit is contained in:
2024-07-29 13:56:28 +08:00
parent da387cc39d
commit 59b56a39dc
6 changed files with 20 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package com.njcn.auth.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import com.njcn.auth.service.UserTokenService;
@@ -44,10 +45,7 @@ import java.security.Principal;
import java.security.interfaces.RSAPublicKey;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -102,14 +100,18 @@ public class AuthController extends BaseController {
username = parameters.get(SecurityConstants.PHONE);
}
//判断当前登录是否超过最大并发数
UserStrategy data = passWordRuleFeugnClient.getUserStrategy().getData();
String onlineUserKey = SecurityConstants.TOKEN_ONLINE_PREFIX;
List<UserTokenInfo> onLineUser = (List<UserTokenInfo>) redisUtil.getLikeListAllValues(onlineUserKey);
if(CollectionUtil.isNotEmpty(onLineUser)){
String finalUsername = username;
onLineUser = onLineUser.stream().filter(item->{
String login = AuthPubUtil.getLoginByToken(item.getRefreshToken());
return !login.equals(finalUsername);
JSONObject jsonObject = AuthPubUtil.getLoginByToken(item.getRefreshToken());
String login = jsonObject.getStr(SecurityConstants.USER_NAME_KEY);
long exp = Long.parseLong(jsonObject.getStr(SecurityConstants.JWT_EXP));
long now = Calendar.getInstance().getTimeInMillis()/1000;
return (exp > now) && !login.equals(finalUsername);
}).collect(Collectors.toList());
}

View File

@@ -33,11 +33,11 @@ public class AuthPubUtil {
@SneakyThrows
public static String getLoginByToken(String token){
public static JSONObject getLoginByToken(String token){
JWSObject jwsObject = JWSObject.parse(token);
String payload = jwsObject.getPayload().toString();
JSONObject jsonObject = JSONUtil.parseObj(payload);
return jsonObject.getStr(SecurityConstants.USER_NAME_KEY);
return jsonObject;
}
}