Skip to content

Commit bf0cc2b

Browse files
authored
adapt to core StringUtils (openhab#15785)
Signed-off-by: Leo Siepel <[email protected]>
1 parent 041c301 commit bf0cc2b

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

bundles/org.openhab.binding.millheat/src/main/java/org/openhab/binding/millheat/internal/handler/MillheatAccountHandler.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
import java.nio.charset.StandardCharsets;
1616
import java.security.MessageDigest;
1717
import java.security.NoSuchAlgorithmException;
18-
import java.security.SecureRandom;
1918
import java.util.List;
2019
import java.util.Optional;
21-
import java.util.Random;
2220
import java.util.concurrent.ExecutionException;
2321
import java.util.concurrent.ScheduledFuture;
2422
import java.util.concurrent.TimeUnit;
@@ -73,6 +71,7 @@
7371
import org.openhab.core.thing.binding.ThingHandler;
7472
import org.openhab.core.types.Command;
7573
import org.openhab.core.util.HexUtils;
74+
import org.openhab.core.util.StringUtils;
7675
import org.osgi.framework.BundleContext;
7776
import org.slf4j.Logger;
7877
import org.slf4j.LoggerFactory;
@@ -93,7 +92,6 @@ public class MillheatAccountHandler extends BaseBridgeHandler {
9392
private static final int NUM_NONCE_CHARS = 16;
9493
private static final String CONTENT_TYPE = "application/x-zc-object";
9594
private static final String ALLOWED_NONCE_CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
96-
private static final int ALLOWED_NONCE_CHARACTERS_LENGTH = ALLOWED_NONCE_CHARACTERS.length();
9795
private static final String REQUEST_TIMEOUT = "300";
9896
public static String authEndpoint = "https://eurouter.ablecloud.cn:9005/zc-account/v1/";
9997
public static String serviceEndpoint = "https://eurouter.ablecloud.cn:9005/millService/v1/";
@@ -107,15 +105,6 @@ public class MillheatAccountHandler extends BaseBridgeHandler {
107105
private @Nullable ScheduledFuture<?> statusFuture;
108106
private @NonNullByDefault({}) MillheatAccountConfiguration config;
109107

110-
private static String getRandomString(final int sizeOfRandomString) {
111-
final Random random = new SecureRandom();
112-
final StringBuilder sb = new StringBuilder(sizeOfRandomString);
113-
for (int i = 0; i < sizeOfRandomString; ++i) {
114-
sb.append(ALLOWED_NONCE_CHARACTERS.charAt(random.nextInt(ALLOWED_NONCE_CHARACTERS_LENGTH)));
115-
}
116-
return sb.toString();
117-
}
118-
119108
public MillheatAccountHandler(final Bridge bridge, final HttpClient httpClient, final BundleContext context) {
120109
super(bridge);
121110
this.httpClient = httpClient;
@@ -343,7 +332,7 @@ private void updateThingStatuses() {
343332
}
344333

345334
private Request buildLoggedInRequest(final AbstractRequest req) throws NoSuchAlgorithmException {
346-
final String nonce = getRandomString(NUM_NONCE_CHARS);
335+
final String nonce = StringUtils.getRandomString(NUM_NONCE_CHARS, ALLOWED_NONCE_CHARACTERS);
347336
final String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
348337
final String signatureBasis = REQUEST_TIMEOUT + timestamp + nonce + token;
349338
MessageDigest md = MessageDigest.getInstance(SHA_1_ALGORITHM);

0 commit comments

Comments
 (0)