mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[digitalstrom] Fix StringIndexOutOfBoundsException (#15318) while keeping removal of StringUtils (#15321)
Signed-off-by: Alexander Friese <af944580@googlemail.com>
This commit is contained in:
parent
9aab0f7d12
commit
f24f0f0251
@ -43,7 +43,6 @@ import javax.net.ssl.SSLSocketFactory;
|
|||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
|
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
|
||||||
import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
|
import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
|
||||||
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
|
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
|
||||||
@ -334,7 +333,12 @@ public class HttpTransportImpl implements HttpTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkNeededSessionToken(String request) {
|
private boolean checkNeededSessionToken(String request) {
|
||||||
String functionName = StringUtils.substringAfterLast(StringUtils.substringBefore(request, "?"), "/");
|
String requestFirstPart = request;
|
||||||
|
int indexOfSeparator = request.indexOf("?");
|
||||||
|
if (indexOfSeparator >= 0) {
|
||||||
|
requestFirstPart = request.substring(0, request.indexOf("?"));
|
||||||
|
}
|
||||||
|
String functionName = requestFirstPart.substring(requestFirstPart.lastIndexOf("/") + 1);
|
||||||
return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName);
|
return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,8 +351,13 @@ public class HttpTransportImpl implements HttpTransport {
|
|||||||
correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken;
|
correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
correctedRequest = StringUtils.replaceOnce(correctedRequest, StringUtils.substringBefore(
|
String strippedRequest = correctedRequest
|
||||||
StringUtils.substringAfter(correctedRequest, ParameterKeys.TOKEN + "="), "&"), sessionToken);
|
.substring(correctedRequest.indexOf(ParameterKeys.TOKEN + "=") + ParameterKeys.TOKEN.length() + 1);
|
||||||
|
int indexOfSeparator = strippedRequest.indexOf("&");
|
||||||
|
if (indexOfSeparator >= 0) {
|
||||||
|
strippedRequest = strippedRequest.substring(0, indexOfSeparator);
|
||||||
|
}
|
||||||
|
correctedRequest = correctedRequest.replaceFirst(strippedRequest, sessionToken);
|
||||||
}
|
}
|
||||||
return correctedRequest;
|
return correctedRequest;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user