|
|
|
@ -33,10 +33,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.authentication.AuthenticationInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.authentication.OAuthAuthenticator;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.constants.RemoteSessionConstants;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.dto.ClientSession;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.dto.DeviceSession;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.dto.common.RemoteSession;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.exception.RemoteSessionInvalidException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.dto.RemoteSession;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.exception.RemoteSessionManagementException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.remote.session.internal.RemoteSessionManagementDataHolder;
|
|
|
|
|
|
|
|
|
@ -53,21 +50,19 @@ import java.util.Map;
|
|
|
|
|
public class RemoteSessionManagementServiceImpl implements RemoteSessionManagementService {
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(RemoteSessionManagementServiceImpl.class);
|
|
|
|
|
private static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
private static final int MAX_BUFFER_SIZE = 640 * 1024;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initializeSession(Session session, String deviceType, String deviceId, String operationId) throws
|
|
|
|
|
RemoteSessionInvalidException, RemoteSessionManagementException {
|
|
|
|
|
|
|
|
|
|
RemoteSessionManagementException {
|
|
|
|
|
|
|
|
|
|
// Check whether required configurations are enabled
|
|
|
|
|
if (!RemoteSessionManagementDataHolder.getInstance().isEnabled()) {
|
|
|
|
|
throw new RemoteSessionManagementException("Remote session feature is disabled.");
|
|
|
|
|
} else if (RemoteSessionManagementDataHolder.getInstance().getServerUrl() == null) {
|
|
|
|
|
throw new RemoteSessionManagementException("Server url haven't been configured.");
|
|
|
|
|
throw new RemoteSessionManagementException("Server url has not been configured.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read Query Parameters for obtain the token
|
|
|
|
|
Map<String, List<String>> sessionQueryParam = new HashedMap();
|
|
|
|
|
List<String> sessionQueryParamList = new LinkedList<>();
|
|
|
|
|
sessionQueryParamList.add(session.getQueryString());
|
|
|
|
@ -78,64 +73,61 @@ public class RemoteSessionManagementServiceImpl implements RemoteSessionManageme
|
|
|
|
|
AuthenticationInfo authenticationInfo = oAuthAuthenticator.isAuthenticated(sessionQueryParam);
|
|
|
|
|
|
|
|
|
|
if (authenticationInfo != null && authenticationInfo.isAuthenticated()) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(authenticationInfo.getTenantDomain()
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(authenticationInfo
|
|
|
|
|
.getTenantDomain()
|
|
|
|
|
, true);
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(authenticationInfo.getUsername());
|
|
|
|
|
if (deviceId != null && !deviceId.isEmpty() && deviceType != null && !deviceType.isEmpty()) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId(deviceId);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
// Check authorization for user
|
|
|
|
|
|
|
|
|
|
// Check authorization of user for given device
|
|
|
|
|
boolean userAuthorized = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getDeviceAccessAuthorizationService()
|
|
|
|
|
.isUserAuthorized(deviceIdentifier, authenticationInfo.getUsername());
|
|
|
|
|
if (userAuthorized) {
|
|
|
|
|
log.info("Operation ID: " + operationId);
|
|
|
|
|
|
|
|
|
|
// set common settings for session
|
|
|
|
|
session.setMaxBinaryMessageBufferSize(MAX_BUFFER_SIZE);
|
|
|
|
|
session.setMaxTextMessageBufferSize(MAX_BUFFER_SIZE);
|
|
|
|
|
session.setMaxBinaryMessageBufferSize(RemoteSessionConstants.MAX_BUFFER_SIZE);
|
|
|
|
|
session.setMaxTextMessageBufferSize(RemoteSessionConstants.MAX_BUFFER_SIZE);
|
|
|
|
|
session.setMaxIdleTimeout(RemoteSessionManagementDataHolder.getInstance().getMaxIdleTimeout());
|
|
|
|
|
|
|
|
|
|
// if session initiated using operatiod id means request came from device
|
|
|
|
|
// if session initiated using operation id means request came from device
|
|
|
|
|
if (operationId != null) {
|
|
|
|
|
Session pendingSession = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getDeviceRequestMap().get((authenticationInfo.getTenantDomain() + "/" + deviceType
|
|
|
|
|
+ "/" + deviceId));
|
|
|
|
|
|
|
|
|
|
if (pendingSession != null) {
|
|
|
|
|
RemoteSession activeSession = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getActiveDeviceClientSessionMap().get((authenticationInfo.getTenantDomain() + "/" +
|
|
|
|
|
deviceType + "/" + deviceId));
|
|
|
|
|
if (activeSession != null) {
|
|
|
|
|
RemoteSession clientRemote = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getSessionMap().get(pendingSession.getId());
|
|
|
|
|
.getSessionMap().get(activeSession.getMySession().getId());
|
|
|
|
|
if (clientRemote != null) {
|
|
|
|
|
|
|
|
|
|
if (clientRemote.getOperationId().equals(operationId)) {
|
|
|
|
|
RemoteSession deviceRemote = new DeviceSession(session, authenticationInfo
|
|
|
|
|
.getTenantDomain(), deviceType, deviceId, operationId);
|
|
|
|
|
RemoteSession deviceRemote = new RemoteSession(session, authenticationInfo
|
|
|
|
|
.getTenantDomain(), deviceType, deviceId);
|
|
|
|
|
deviceRemote.setOperationId(operationId);
|
|
|
|
|
deviceRemote.setPeerSession(clientRemote);
|
|
|
|
|
clientRemote.setPeerSession(deviceRemote);
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getSessionMap().put(session
|
|
|
|
|
.getId(), deviceRemote);
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getDeviceRequestMap().remove(
|
|
|
|
|
(authenticationInfo.getTenantDomain() + "/" + deviceType + "/" + deviceId));
|
|
|
|
|
// Send Remote connect response
|
|
|
|
|
JSONObject message = new JSONObject();
|
|
|
|
|
message.put("code", RemoteSessionConstants.REMOTE_CONNECT);
|
|
|
|
|
message.put("operation_response", "connected");
|
|
|
|
|
message.put(RemoteSessionConstants.REMOTE_CONNECT_CODE, RemoteSessionConstants
|
|
|
|
|
.REMOTE_CONNECT);
|
|
|
|
|
deviceRemote.sendMessageToPeer(message.toString());
|
|
|
|
|
|
|
|
|
|
log.info("Device session opened for session id: " + session.getId() +
|
|
|
|
|
" device Type : " + deviceType + " , " + "deviceId : " + deviceId);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionManagementException("Device and Operation information does" +
|
|
|
|
|
" not matched with client information for operation id: " + operationId +
|
|
|
|
|
" device Type : " + deviceType + " , " + "deviceId : " +
|
|
|
|
|
throw new RemoteSessionManagementException("Device and Operation information " +
|
|
|
|
|
"does not matched with client information for operation id: " +
|
|
|
|
|
operationId + " device Type : " + deviceType + " , " + "deviceId : " +
|
|
|
|
|
deviceId);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionManagementException("Device session is inactive for operation " +
|
|
|
|
|
"id: " + operationId + " device Type : " + deviceType + " , " + "deviceId : " +
|
|
|
|
|
deviceId);
|
|
|
|
|
throw new RemoteSessionManagementException("Device session is inactive for " +
|
|
|
|
|
"operation id: " + operationId + " device Type : " + deviceType + " , " +
|
|
|
|
|
"deviceId : " + deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -144,19 +136,34 @@ public class RemoteSessionManagementServiceImpl implements RemoteSessionManageme
|
|
|
|
|
"id: " + operationId + " device Type : " + deviceType + " , " + "deviceId : " +
|
|
|
|
|
deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
RemoteSession clientRemote = new RemoteSession(session, authenticationInfo
|
|
|
|
|
.getTenantDomain(), deviceType, deviceId);
|
|
|
|
|
// Create new remote control operation to start the session
|
|
|
|
|
Session pendingSession = RemoteSessionManagementDataHolder.getInstance().getDeviceRequestMap().get(
|
|
|
|
|
(authenticationInfo.getTenantDomain() + "/" + deviceType + "/" + deviceId));
|
|
|
|
|
if (pendingSession != null && pendingSession.isOpen()) {
|
|
|
|
|
throw new RemoteSessionManagementException("Another client session waiting on device to connect.");
|
|
|
|
|
RemoteSession activeSession = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getActiveDeviceClientSessionMap().putIfAbsent((authenticationInfo
|
|
|
|
|
.getTenantDomain() + "/" + deviceType + "/" + deviceId),
|
|
|
|
|
clientRemote);
|
|
|
|
|
if (activeSession != null && activeSession.getMySession().isOpen() && activeSession
|
|
|
|
|
.getPeerSession() == null) {
|
|
|
|
|
throw new RemoteSessionManagementException("Another client session waiting on device " +
|
|
|
|
|
"to connect.");
|
|
|
|
|
} else {
|
|
|
|
|
Session lastSession = RemoteSessionManagementDataHolder.getInstance().getDeviceRequestMap().putIfAbsent(
|
|
|
|
|
(authenticationInfo.getTenantDomain() + "/" + deviceType + "/" + deviceId),
|
|
|
|
|
session);
|
|
|
|
|
// if there is pending session exists but already closed, then we need to remove it.
|
|
|
|
|
if (activeSession != null) {
|
|
|
|
|
endSession(activeSession.getMySession(), "Remote session closed due to new session" +
|
|
|
|
|
" request");
|
|
|
|
|
// Use put if absent for adding session to waiting list since we need to overcome
|
|
|
|
|
// multithreaded session requests.
|
|
|
|
|
activeSession = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getActiveDeviceClientSessionMap().putIfAbsent((authenticationInfo
|
|
|
|
|
.getTenantDomain() + "/" + deviceType + "/" +
|
|
|
|
|
deviceId), clientRemote);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lastSession == null) {
|
|
|
|
|
// If another client tried to start session same time then active session will be
|
|
|
|
|
// exist. So we are adding session request only no parallel sessions added to map
|
|
|
|
|
if (activeSession == null) {
|
|
|
|
|
|
|
|
|
|
// Create operation if session initiated by client
|
|
|
|
|
Operation operation = new ConfigOperation();
|
|
|
|
@ -164,55 +171,58 @@ public class RemoteSessionManagementServiceImpl implements RemoteSessionManageme
|
|
|
|
|
operation.setEnabled(true);
|
|
|
|
|
operation.setControl(Operation.Control.NO_REPEAT);
|
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
|
payload.put("serverUrl", RemoteSessionManagementDataHolder.getInstance().getServerUrl());
|
|
|
|
|
payload.put("serverUrl", RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getServerUrl());
|
|
|
|
|
operation.setPayLoad(payload.toString());
|
|
|
|
|
String date = new SimpleDateFormat(DATE_FORMAT_NOW).format(new Date());
|
|
|
|
|
String date = new SimpleDateFormat(RemoteSessionConstants.DATE_FORMAT_NOW).format
|
|
|
|
|
(new Date());
|
|
|
|
|
operation.setCreatedTimeStamp(date);
|
|
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
|
deviceIdentifiers.add(new DeviceIdentifier(deviceId, deviceType));
|
|
|
|
|
Activity activity = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getDeviceManagementProviderService().addOperation(deviceType, operation,
|
|
|
|
|
deviceIdentifiers);
|
|
|
|
|
log.info("Activity id: " + activity.getActivityId());
|
|
|
|
|
clientRemote.setOperationId(activity.getActivityId()
|
|
|
|
|
.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getSessionMap().put(session.getId
|
|
|
|
|
(), clientRemote);
|
|
|
|
|
log.info("Client remote session opened for session id: " + session.getId() +
|
|
|
|
|
" device Type : " + deviceType + " , " + "deviceId : " + deviceId);
|
|
|
|
|
|
|
|
|
|
RemoteSession clientRemote = new ClientSession(session, authenticationInfo
|
|
|
|
|
.getTenantDomain(), deviceType, deviceId, activity.getActivityId().replace(DeviceManagementConstants
|
|
|
|
|
.OperationAttributes.ACTIVITY, ""));
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getSessionMap().put(session.getId(), clientRemote);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionManagementException("Another client session waiting on " +
|
|
|
|
|
"device to connect.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("Current session count: " + RemoteSessionManagementDataHolder
|
|
|
|
|
.getInstance().getSessionMap().size());
|
|
|
|
|
log.info("Current remote sessions count: " + RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getSessionMap().size());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionInvalidException("Missing device Id or type ", new CloseReason
|
|
|
|
|
(CloseReason.CloseCodes.CANNOT_ACCEPT, "Missing device Id or device type "));
|
|
|
|
|
throw new RemoteSessionManagementException("Missing device Id or type ");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionInvalidException("Unauthorized Access for the device Type : " + deviceType
|
|
|
|
|
+ " , deviceId : " + deviceId, new CloseReason(CloseReason.CloseCodes.CANNOT_ACCEPT,
|
|
|
|
|
"Unauthorized Access"));
|
|
|
|
|
throw new RemoteSessionManagementException("Unauthorized Access for the device Type : " + deviceType
|
|
|
|
|
+ " , deviceId : " + deviceId);
|
|
|
|
|
}
|
|
|
|
|
} catch (OperationManagementException | InvalidDeviceException e) {
|
|
|
|
|
throw new RemoteSessionManagementException("Error occurred while adding initial operation for the device Type : " +
|
|
|
|
|
deviceType + " , deviceId : " + deviceId, e);
|
|
|
|
|
throw new RemoteSessionManagementException("Error occurred while adding initial operation for the " +
|
|
|
|
|
"device Type : " + deviceType + " , deviceId : " + deviceId);
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new RemoteSessionManagementException("Error occurred while device access authorization for the device Type : " +
|
|
|
|
|
deviceType + " , " + "deviceId : " + deviceId, e);
|
|
|
|
|
throw new RemoteSessionManagementException("Error occurred while device access authorization for the " +
|
|
|
|
|
"device Type : " + deviceType + " , " + "deviceId : " + deviceId);
|
|
|
|
|
} finally {
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionInvalidException("Invalid token", new CloseReason(CloseReason.CloseCodes
|
|
|
|
|
.CANNOT_ACCEPT, "Invalid token"));
|
|
|
|
|
throw new RemoteSessionManagementException("Invalid token");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initializeSession(Session session, String deviceType, String deviceId) throws RemoteSessionInvalidException, RemoteSessionManagementException {
|
|
|
|
|
public void initializeSession(Session session, String deviceType, String deviceId) throws
|
|
|
|
|
RemoteSessionManagementException {
|
|
|
|
|
initializeSession(session, deviceType, deviceId, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -221,22 +231,18 @@ public class RemoteSessionManagementServiceImpl implements RemoteSessionManageme
|
|
|
|
|
*
|
|
|
|
|
* @param session Web socket RemoteSession
|
|
|
|
|
* @param message String message needs to send to peer connection
|
|
|
|
|
* @throws RemoteSessionInvalidException throws when session cannot be made due to invalid data
|
|
|
|
|
* @throws RemoteSessionManagementException throws when session cannot be made due to invalid data
|
|
|
|
|
* @throws RemoteSessionManagementException throws when session has error with accessing device resources
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void sendMessageToPeer(Session session, String message) throws RemoteSessionManagementException,
|
|
|
|
|
RemoteSessionInvalidException {
|
|
|
|
|
public void sendMessageToPeer(Session session, String message) throws RemoteSessionManagementException {
|
|
|
|
|
JSONObject jsonObject = new JSONObject(message);
|
|
|
|
|
RemoteSession remoteSession = RemoteSessionManagementDataHolder.getInstance().getSessionMap().get(session.getId());
|
|
|
|
|
RemoteSession remoteSession = RemoteSessionManagementDataHolder.getInstance().getSessionMap().get(session
|
|
|
|
|
.getId());
|
|
|
|
|
if (remoteSession != null) {
|
|
|
|
|
if (remoteSession instanceof ClientSession) {
|
|
|
|
|
jsonObject.put("id", remoteSession.getOperationId());
|
|
|
|
|
}
|
|
|
|
|
remoteSession.sendMessageToPeer(jsonObject.toString());
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionInvalidException("Remote Session cannot be found ", new CloseReason(CloseReason
|
|
|
|
|
.CloseCodes.CANNOT_ACCEPT, "Invalid RemoteSession"));
|
|
|
|
|
throw new RemoteSessionManagementException("Remote Session cannot be found ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -246,48 +252,68 @@ public class RemoteSessionManagementServiceImpl implements RemoteSessionManageme
|
|
|
|
|
*
|
|
|
|
|
* @param session Web socket RemoteSession
|
|
|
|
|
* @param message Byte message needs to send to peer connection
|
|
|
|
|
* @throws RemoteSessionInvalidException throws when session cannot be made due to invalid data
|
|
|
|
|
* @throws RemoteSessionManagementException throws when session cannot be made due to invalid data
|
|
|
|
|
* @throws RemoteSessionManagementException throws when session has error with accessing device resources
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void sendMessageToPeer(Session session, byte[] message) throws RemoteSessionInvalidException,
|
|
|
|
|
RemoteSessionManagementException {
|
|
|
|
|
public void sendMessageToPeer(Session session, byte[] message) throws RemoteSessionManagementException {
|
|
|
|
|
|
|
|
|
|
RemoteSession remoteSession = RemoteSessionManagementDataHolder.getInstance().getSessionMap().get(session.getId());
|
|
|
|
|
RemoteSession remoteSession = RemoteSessionManagementDataHolder.getInstance().getSessionMap().get(session
|
|
|
|
|
.getId());
|
|
|
|
|
if (remoteSession != null) {
|
|
|
|
|
remoteSession.sendMessageToPeer(message);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RemoteSessionInvalidException("Remote Session cannot be found ", new CloseReason(CloseReason
|
|
|
|
|
.CloseCodes.CANNOT_ACCEPT, "Invalid RemoteSession"));
|
|
|
|
|
throw new RemoteSessionManagementException("Remote Session cannot be found ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Closing the session and cleanup the resources
|
|
|
|
|
*
|
|
|
|
|
* @param session Web socket RemoteSession
|
|
|
|
|
* @param session Web socket Remote Session
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void endSession(Session session) throws IOException {
|
|
|
|
|
|
|
|
|
|
RemoteSession remoteSession = RemoteSessionManagementDataHolder.getInstance().getSessionMap().remove(session.getId());
|
|
|
|
|
public void endSession(Session session, String closeReason) {
|
|
|
|
|
log.info("Closing session: "+session.getId()+" due to:"+ closeReason);
|
|
|
|
|
RemoteSession remoteSession = RemoteSessionManagementDataHolder.getInstance().getSessionMap().remove(session
|
|
|
|
|
.getId());
|
|
|
|
|
if (remoteSession != null) {
|
|
|
|
|
String operationId = remoteSession.getOperationId();
|
|
|
|
|
if (remoteSession.getPeerSession() != null) {
|
|
|
|
|
Session peerSession = remoteSession.getPeerSession().getMySession();
|
|
|
|
|
if (peerSession != null) {
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getSessionMap().remove(peerSession.getId());
|
|
|
|
|
if (peerSession.isOpen()) {
|
|
|
|
|
peerSession.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Remote session closed"));
|
|
|
|
|
try {
|
|
|
|
|
peerSession.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, closeReason));
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.error("Failed to disconnect the client.", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (remoteSession.getMySession() != null) {
|
|
|
|
|
Session mySession = remoteSession.getMySession();
|
|
|
|
|
if (mySession.isOpen()) {
|
|
|
|
|
try {
|
|
|
|
|
mySession.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, closeReason));
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.error("Failed to disconnect the client.", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (operationId != null) {
|
|
|
|
|
Session lastSession = RemoteSessionManagementDataHolder.getInstance().getDeviceRequestMap().get(
|
|
|
|
|
(remoteSession.getTenantDomain() + "/" + remoteSession.getDeviceType() + "/" + remoteSession
|
|
|
|
|
.getDeviceId()));
|
|
|
|
|
if (lastSession != null && lastSession.getId().equals(session.getId())) {
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getDeviceRequestMap().remove(
|
|
|
|
|
(remoteSession.getTenantDomain() + "/" + remoteSession.getDeviceType() + "/" + remoteSession
|
|
|
|
|
.getDeviceId()));
|
|
|
|
|
String deviceIdentifier = remoteSession.getTenantDomain() + "/" + remoteSession
|
|
|
|
|
.getDeviceType() + "/" + remoteSession.getDeviceId();
|
|
|
|
|
RemoteSession lastSession = RemoteSessionManagementDataHolder.getInstance()
|
|
|
|
|
.getActiveDeviceClientSessionMap().get(deviceIdentifier);
|
|
|
|
|
if (lastSession != null && lastSession.getMySession().getId().equals(session.getId())) {
|
|
|
|
|
RemoteSessionManagementDataHolder.getInstance().getActiveDeviceClientSessionMap().remove
|
|
|
|
|
(deviceIdentifier);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|