|
|
|
@ -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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|