adapt to core StringUtils (#15787)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
468a245ab8
commit
041c30159d
|
@ -17,7 +17,6 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
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.types.Command;
|
||||
import org.openhab.core.types.TypeParser;
|
||||
import org.openhab.core.util.StringUtils;
|
||||
import org.openhab.io.openhabcloud.NotificationAction;
|
||||
import org.osgi.framework.BundleContext;
|
||||
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_REQUEST_TIMEOUT = 30000;
|
||||
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);
|
||||
|
||||
|
@ -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>
|
||||
* directory. An existing <code>secret</code> file won't be overwritten.
|
||||
|
@ -310,7 +300,7 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
|
|||
String newSecretString = "";
|
||||
|
||||
if (!file.exists()) {
|
||||
newSecretString = randomString(20);
|
||||
newSecretString = StringUtils.getRandomAlphanumeric(20);
|
||||
logger.debug("New secret = {}", censored(newSecretString));
|
||||
writeFile(file, newSecretString);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue