优化用户session逻辑
This commit is contained in:
@@ -20,7 +20,7 @@ import win.liyufan.im.IMTopic;
|
||||
public class GetTokenHandler extends IMHandler<WFCMessage.GetTokenRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.GetTokenRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
MemorySessionStore.Session session = m_sessionsStore.createUserSession(fromUser, clientID, request.getPlatform());
|
||||
MemorySessionStore.Session session = m_sessionsStore.updateOrCreateUserSession(fromUser, clientID, request.getPlatform());
|
||||
TokenAuthenticator authenticator = new TokenAuthenticator();
|
||||
String strToken = authenticator.generateToken(fromUser);
|
||||
String result = strToken + "|" + session.getSecret() + "|" + session.getDbSecret();
|
||||
|
||||
@@ -328,16 +328,27 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session createUserSession(String username, String clientID, int platform) {
|
||||
public Session updateOrCreateUserSession(String username, String clientID, int platform) {
|
||||
LOG.debug("createUserSession for client <{}>, user <{}>", clientID, username);
|
||||
|
||||
ClientSession clientSession = new ClientSession(clientID, this);
|
||||
Session session = databaseStore.getSession(username, clientID, clientSession);
|
||||
Session session = sessions.get(clientID);
|
||||
|
||||
if (session == null) {
|
||||
session = databaseStore.createSession(username, clientID, clientSession, platform);
|
||||
if (session == null || !session.username.equals(username)) {
|
||||
if (session != null && !session.username.equals(username)) {
|
||||
if (userSessions.get(username) != null) {
|
||||
userSessions.get(username).remove(clientID);
|
||||
}
|
||||
}
|
||||
ClientSession clientSession = new ClientSession(clientID, this);
|
||||
session = databaseStore.getSession(username, clientID, clientSession);
|
||||
|
||||
if (session == null) {
|
||||
session = databaseStore.createSession(username, clientID, clientSession, platform);
|
||||
}
|
||||
sessions.put(clientID, session);
|
||||
}
|
||||
|
||||
|
||||
if (session.getDeleted() > 0) {
|
||||
session.setDeleted(0);
|
||||
databaseStore.updateSessionDeleted(username, clientID, 0);
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface ISessionsStore {
|
||||
*/
|
||||
boolean contains(String clientID);
|
||||
|
||||
Session createUserSession(String username, String clientID, int platform);
|
||||
Session updateOrCreateUserSession(String username, String clientID, int platform);
|
||||
|
||||
ErrorCode loadActiveSession(String username, String clientID);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user