Skip to content

Commit

Permalink
[digitalstrom] Fix StringIndexOutOfBoundsException (openhab#15318) wh…
Browse files Browse the repository at this point in the history
…ile keeping removal of StringUtils (openhab#15321)

Signed-off-by: Alexander Friese <af944580@googlemail.com>
  • Loading branch information
alexf2015 authored Jul 29, 2023
1 parent 9aab0f7 commit f24f0f0
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import javax.net.ssl.TrustManager;
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.manager.ConnectionManager;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
Expand Down Expand Up @@ -334,7 +333,12 @@ private String checkSessionToken(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);
}

Expand All @@ -347,8 +351,13 @@ private String addSessionToken(String request, String sessionToken) {
correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken;
}
} else {
correctedRequest = StringUtils.replaceOnce(correctedRequest, StringUtils.substringBefore(
StringUtils.substringAfter(correctedRequest, ParameterKeys.TOKEN + "="), "&"), sessionToken);
String strippedRequest = correctedRequest
.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;
}
Expand Down

0 comments on commit f24f0f0

Please sign in to comment.