17
17
import java .io .IOException ;
18
18
import java .nio .charset .StandardCharsets ;
19
19
import java .nio .file .Files ;
20
- import java .security .SecureRandom ;
21
20
import java .util .Arrays ;
22
21
import java .util .HashSet ;
23
22
import java .util .List ;
47
46
import org .openhab .core .net .HttpServiceUtil ;
48
47
import org .openhab .core .types .Command ;
49
48
import org .openhab .core .types .TypeParser ;
49
+ import org .openhab .core .util .StringUtils ;
50
50
import org .openhab .io .openhabcloud .NotificationAction ;
51
51
import org .osgi .framework .BundleContext ;
52
52
import org .osgi .framework .Constants ;
@@ -80,8 +80,6 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
80
80
private static final int DEFAULT_LOCAL_OPENHAB_MAX_CONCURRENT_REQUESTS = 200 ;
81
81
private static final int DEFAULT_LOCAL_OPENHAB_REQUEST_TIMEOUT = 30000 ;
82
82
private static final String HTTPCLIENT_NAME = "openhabcloud" ;
83
- private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
84
- private static final SecureRandom SR = new SecureRandom ();
85
83
86
84
private final Logger logger = LoggerFactory .getLogger (CloudService .class );
87
85
@@ -292,14 +290,6 @@ private void writeFile(File file, String content) {
292
290
}
293
291
}
294
292
295
- private String randomString (int length ) {
296
- StringBuilder sb = new StringBuilder (length );
297
- for (int i = 0 ; i < length ; i ++) {
298
- sb .append (CHARS .charAt (SR .nextInt (CHARS .length ())));
299
- }
300
- return sb .toString ();
301
- }
302
-
303
293
/**
304
294
* Creates a random secret and writes it to the <code>userdata/openhabcloud</code>
305
295
* directory. An existing <code>secret</code> file won't be overwritten.
@@ -310,7 +300,7 @@ private String getSecret() {
310
300
String newSecretString = "" ;
311
301
312
302
if (!file .exists ()) {
313
- newSecretString = randomString (20 );
303
+ newSecretString = StringUtils . getRandomAlphanumeric (20 );
314
304
logger .debug ("New secret = {}" , censored (newSecretString ));
315
305
writeFile (file , newSecretString );
316
306
} else {
0 commit comments