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