Add constants to common class

merge-requests/1/head
warunalakshitha 7 years ago
parent dde525dd91
commit 4c56d65925

@ -23,7 +23,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>remote-session-extension</artifactId>
<version>4.0.66-SNAPSHOT</version>
<version>4.0.87-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>remote-session-extension</artifactId>
<version>4.0.66-SNAPSHOT</version>
<version>4.0.87-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -28,18 +28,18 @@ import java.io.IOException;
public interface RemoteSessionManagementService {
/**
* Initialize session based on web socket request .this method use by the device to connect
* Initialize session based on web socket request .This method is used by the device to connect
*
* @param session Web socket RemoteSession
* @param deviceType Device Type
* @param deviceId Device Id
* @throws RemoteSessionManagementException throws when session has errors with accessing device resources
*/
public void initializeSession(Session session, String deviceType, String deviceId) throws
void initializeSession(Session session, String deviceType, String deviceId) throws
RemoteSessionManagementException;
/**
* Initialize session based on web socket request . This method use by the device to connect
* Initialize session based on web socket request . This method is used by the device to connect
*
* @param session Web socket RemoteSession
* @param deviceType Device Type
@ -47,7 +47,7 @@ public interface RemoteSessionManagementService {
* @param operationId Operation Id that device needs to connec
* @throws RemoteSessionManagementException throws when session has errors with accessing device resources
*/
public void initializeSession(Session session, String deviceType, String deviceId, String operationId) throws
void initializeSession(Session session, String deviceType, String deviceId, String operationId) throws
RemoteSessionManagementException;
/**
@ -57,7 +57,7 @@ public interface RemoteSessionManagementService {
* @param message Message needs to send to peer connection client
* @throws RemoteSessionManagementException
*/
public void sendMessageToPeer(Session session, String message) throws RemoteSessionManagementException;
void sendMessageToPeer(Session session, String message) throws RemoteSessionManagementException;
/**
* Send byte message to connected remote device or client
@ -66,13 +66,13 @@ public interface RemoteSessionManagementService {
* @param message Message needs to send to peer connection
* @throws RemoteSessionManagementException
*/
public void sendMessageToPeer(Session session, byte[] message) throws RemoteSessionManagementException;
void sendMessageToPeer(Session session, byte[] message) throws RemoteSessionManagementException;
/**
* Close the session
*
* @param session Web socket RemoteSession
*/
public void endSession(Session session,String closeReason);
void endSession(Session session, String closeReason);
}

@ -47,6 +47,10 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Class @{@link RemoteSessionManagementServiceImpl} is the implementation of @{@link RemoteSessionManagementService}
* which is used manage initial connection, sending messages to peer session, manage and close the session.
*/
public class RemoteSessionManagementServiceImpl implements RemoteSessionManagementService {
private static final Log log = LogFactory.getLog(RemoteSessionManagementServiceImpl.class);

@ -27,7 +27,6 @@ import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_
import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationResponseDTO;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.List;
@ -41,14 +40,6 @@ public class OAuthTokenValidator {
private static String cookie;
private GenericObjectPool stubs;
private static Log log = LogFactory.getLog(OAuthTokenValidator.class);
private static final String COOKIE_KEY_VALUE_SEPERATOR = "=";
private static final String COOKIE_KEYPAIR_SEPERATOR = ";";
private static final String COOKIE = "cookie";
private static final String TOKEN_TYPE = "bearer";
private static final String TOKEN_IDENTIFIER = "websocketToken";
private static final String QUERY_STRING_SEPERATOR = "&";
private static final String QUERY_KEY_VALUE_SEPERATOR = "=";
private static final String QUERY_STRING = "queryString";
private static OAuthTokenValidator oAuthTokenValidator;
@ -58,6 +49,7 @@ public class OAuthTokenValidator {
/**
* This method gets a string accessToken and validates it
*
* @param webSocketConnectionProperties WebSocket connection information including http headers
* @return AuthenticationInfo with the validated results.
*/
@ -118,7 +110,7 @@ public class OAuthTokenValidator {
OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
accessToken.setTokenType(TOKEN_TYPE);
accessToken.setTokenType(RemoteSessionConstants.OAuthTokenValidator.TOKEN_TYPE);
accessToken.setIdentifier(token);
validationRequest.setAccessToken(accessToken);
boolean authenticated;
@ -155,16 +147,20 @@ public class OAuthTokenValidator {
/**
* Retrieving the token from the http header
*
* @param webSocketConnectionProperties WebSocket connection information including http headers
* @return retrieved token
*/
private String getToken(Map<String, List<String>> webSocketConnectionProperties) {
String cookieString = webSocketConnectionProperties.get(COOKIE).get(0);
String[] properties = cookieString.split(COOKIE_KEYPAIR_SEPERATOR);
String cookieString = webSocketConnectionProperties.get(RemoteSessionConstants.OAuthTokenValidator.COOKIE)
.get(0);
String[] properties = cookieString.split(RemoteSessionConstants.OAuthTokenValidator.COOKIE_KEYPAIR_SEPERATOR);
String token;
for (String keyValuePair: properties) {
if(TOKEN_IDENTIFIER.equals((keyValuePair.split(COOKIE_KEY_VALUE_SEPERATOR)[0]).trim())){
token = (keyValuePair.split(COOKIE_KEY_VALUE_SEPERATOR)[1]).trim();
for (String keyValuePair : properties) {
if (RemoteSessionConstants.OAuthTokenValidator.TOKEN_IDENTIFIER.equals((keyValuePair.
split(RemoteSessionConstants.OAuthTokenValidator.COOKIE_KEY_VALUE_SEPERATOR)[0]).trim())) {
token = (keyValuePair.split(RemoteSessionConstants.OAuthTokenValidator.COOKIE_KEY_VALUE_SEPERATOR)
[1]).trim();
return token;
}
}
@ -174,20 +170,24 @@ public class OAuthTokenValidator {
/**
* Retrieving the token from the http session
*
* @param webSocketConnectionProperties WebSocket connection information including http headers
* @return retrieved token
*/
private String getTokenFromSession(Map<String, List<String>> webSocketConnectionProperties) {
String queryString = webSocketConnectionProperties.get(QUERY_STRING).get(0);
String queryString = webSocketConnectionProperties.get(RemoteSessionConstants.OAuthTokenValidator
.QUERY_STRING).get(0);
if (queryString != null) {
String[] allQueryParamPairs = queryString.split(QUERY_STRING_SEPERATOR);
String[] allQueryParamPairs = queryString.split(RemoteSessionConstants.OAuthTokenValidator
.QUERY_STRING_SEPERATOR);
for (String keyValuePair : allQueryParamPairs) {
String[] queryParamPair = keyValuePair.split(QUERY_KEY_VALUE_SEPERATOR);
String[] queryParamPair = keyValuePair.split(RemoteSessionConstants.OAuthTokenValidator
.QUERY_KEY_VALUE_SEPERATOR);
if (queryParamPair.length != 2) {
log.warn("Invalid query string [" + queryString + "] passed in.");
break;
}
if (queryParamPair[0].equals(TOKEN_IDENTIFIER)) {
if (queryParamPair[0].equals(RemoteSessionConstants.OAuthTokenValidator.TOKEN_IDENTIFIER)) {
return queryParamPair[1];
}
}

@ -143,8 +143,7 @@ public class OAuthTokenValidatorStubFactory extends BasePoolableObjectFactory {
*/
private EasySSLProtocolSocketFactory createProtocolSocketFactory() throws OAuthTokenValidationException {
try {
EasySSLProtocolSocketFactory easySSLPSFactory = new EasySSLProtocolSocketFactory();
return easySSLPSFactory;
return new EasySSLProtocolSocketFactory();
} catch (IOException e) {
String errorMsg = "Failed to initiate EasySSLProtocolSocketFactory.";
throw new OAuthTokenValidationException(errorMsg, e);

@ -44,4 +44,21 @@ public class RemoteSessionConstants {
private RemoteSessionConstants() {
}
/**
* OAuthTokenValidator specific constants
*/
public final class OAuthTokenValidator {
public static final String COOKIE_KEY_VALUE_SEPERATOR = "=";
public static final String COOKIE_KEYPAIR_SEPERATOR = ";";
public static final String COOKIE = "cookie";
public static final String TOKEN_TYPE = "bearer";
public static final String TOKEN_IDENTIFIER = "websocketToken";
public static final String QUERY_STRING_SEPERATOR = "&";
public static final String QUERY_KEY_VALUE_SEPERATOR = "=";
public static final String QUERY_STRING = "queryString";
private OAuthTokenValidator() {
}
}
}

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>extensions</artifactId>
<version>4.0.66-SNAPSHOT</version>
<version>4.0.87-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -3,14 +3,14 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>extensions-feature</artifactId>
<version>4.0.66-SNAPSHOT</version>
<version>4.0.87-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.remote.session.feature</artifactId>
<packaging>pom</packaging>
<version>4.0.66-SNAPSHOT</version>
<version>4.0.87-SNAPSHOT</version>
<name>WSO2 Carbon - Remote Session Manager</name>
<url>http://wso2.org</url>
<description>This feature contains the core bundles required iot Remote Sessions</description>

Loading…
Cancel
Save