去掉一个token只记录一个ws连接的限制
This commit is contained in:
parent
bd58435a06
commit
c937230ed5
@ -18,12 +18,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DefaultSubscribeManager {
|
||||
/**
|
||||
* 暂时限制一个token只能对应一个wsSessionId
|
||||
* k - token
|
||||
* v - wsSessionId
|
||||
*/
|
||||
public static final Map<String, String> tokenSessionMap = new ConcurrentHashMap<>();
|
||||
// /**
|
||||
// * 暂时限制一个token只能对应一个wsSessionId
|
||||
// * k - token
|
||||
// * v - wsSessionId
|
||||
// */
|
||||
// public static final Map<String, String> tokenSessionMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* key-wsSessionId
|
||||
* val-simulationId
|
||||
@ -44,11 +44,11 @@ public class DefaultSubscribeManager {
|
||||
public void disconnect(WebsocketConfig.MyPrincipal user, String wsSessionId) {
|
||||
if (wsSessionId == null)
|
||||
return;
|
||||
String token = user.getToken();
|
||||
String connectedSession = tokenSessionMap.get(token);
|
||||
if (wsSessionId.equals(connectedSession)) { //当前的sessionId和要断开的一致
|
||||
tokenSessionMap.remove(token);
|
||||
}
|
||||
// String token = user.getToken();
|
||||
// String connectedSession = tokenSessionMap.get(token);
|
||||
// if (wsSessionId.equals(connectedSession)) { //当前的sessionId和要断开的一致
|
||||
// tokenSessionMap.remove(token);
|
||||
// }
|
||||
String sid = wsSidMap.remove(wsSessionId);
|
||||
if (sid == null) {
|
||||
return;
|
||||
@ -66,13 +66,13 @@ public class DefaultSubscribeManager {
|
||||
}
|
||||
|
||||
public synchronized void subscribe(WebsocketConfig.MyPrincipal user, String wsSessionId, String subId, String destination) {
|
||||
String token = user.getToken();
|
||||
String oldSession = tokenSessionMap.get(token);
|
||||
if (!wsSessionId.equals(oldSession)) { //一个token出现多次连接
|
||||
disconnect(user, oldSession); //断开旧连接
|
||||
}
|
||||
|
||||
tokenSessionMap.put(token, wsSessionId); //记录新连接
|
||||
// String token = user.getToken();
|
||||
// String oldSession = tokenSessionMap.get(token);
|
||||
// if (!wsSessionId.equals(oldSession)) { //一个token出现多次连接
|
||||
// disconnect(user, oldSession); //断开旧连接
|
||||
// }
|
||||
//
|
||||
// tokenSessionMap.put(token, wsSessionId); //记录新连接
|
||||
if (destination.startsWith("/user")) {
|
||||
destination = destination.substring(5);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user