adapt to core StringUtils (#15787)

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-10-21 11:54:50 +02:00 committed by GitHub
parent 468a245ab8
commit 041c30159d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 12 deletions

View File

@ -17,7 +17,6 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.security.SecureRandom;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -47,6 +46,7 @@ import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.net.HttpServiceUtil; import org.openhab.core.net.HttpServiceUtil;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
import org.openhab.core.types.TypeParser; import org.openhab.core.types.TypeParser;
import org.openhab.core.util.StringUtils;
import org.openhab.io.openhabcloud.NotificationAction; import org.openhab.io.openhabcloud.NotificationAction;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants; import org.osgi.framework.Constants;
@ -80,8 +80,6 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
private static final int DEFAULT_LOCAL_OPENHAB_MAX_CONCURRENT_REQUESTS = 200; private static final int DEFAULT_LOCAL_OPENHAB_MAX_CONCURRENT_REQUESTS = 200;
private static final int DEFAULT_LOCAL_OPENHAB_REQUEST_TIMEOUT = 30000; private static final int DEFAULT_LOCAL_OPENHAB_REQUEST_TIMEOUT = 30000;
private static final String HTTPCLIENT_NAME = "openhabcloud"; private static final String HTTPCLIENT_NAME = "openhabcloud";
private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static final SecureRandom SR = new SecureRandom();
private final Logger logger = LoggerFactory.getLogger(CloudService.class); private final Logger logger = LoggerFactory.getLogger(CloudService.class);
@ -292,14 +290,6 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
} }
} }
private String randomString(int length) {
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
sb.append(CHARS.charAt(SR.nextInt(CHARS.length())));
}
return sb.toString();
}
/** /**
* Creates a random secret and writes it to the <code>userdata/openhabcloud</code> * Creates a random secret and writes it to the <code>userdata/openhabcloud</code>
* directory. An existing <code>secret</code> file won't be overwritten. * directory. An existing <code>secret</code> file won't be overwritten.
@ -310,7 +300,7 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
String newSecretString = ""; String newSecretString = "";
if (!file.exists()) { if (!file.exists()) {
newSecretString = randomString(20); newSecretString = StringUtils.getRandomAlphanumeric(20);
logger.debug("New secret = {}", censored(newSecretString)); logger.debug("New secret = {}", censored(newSecretString));
writeFile(file, newSecretString); writeFile(file, newSecretString);
} else { } else {