11package uz .server .service ;
22
3+ import java .security .SecureRandom ;
4+ import java .util .Objects ;
5+ import java .util .Optional ;
36import lombok .RequiredArgsConstructor ;
47import lombok .extern .slf4j .Slf4j ;
58import org .springframework .stereotype .Service ;
912import uz .server .domain .exception .BaseException ;
1013import uz .server .repository .TunnelRepository ;
1114
12- import java .security .SecureRandom ;
13- import java .util .Objects ;
14- import java .util .Optional ;
15-
1615@ Service
1716@ RequiredArgsConstructor
1817@ Slf4j
1918public class TunnelService {
2019 private final TunnelRepository repo ;
2120
21+ private static final SecureRandom RANDOM = new SecureRandom ();
22+ private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
23+
2224 public String create (String sessionId , User user , String customSubdomain ) {
2325 log .info ("Creating tunnel: userId={}" , user .getId ());
2426 Integer count = repo .countByUser (user );
@@ -45,18 +47,15 @@ public String create(String sessionId, User user, String customSubdomain) {
4547 }
4648
4749 private String generateUniqueString () {
48- long timestamp = System .currentTimeMillis () % 100000 ;
49- StringBuilder sb = new StringBuilder ();
50- SecureRandom RANDOM = new SecureRandom ( );
50+ long timestamp = System .currentTimeMillis ();
51+ StringBuilder sb = new StringBuilder ();
52+ sb . append ( timestamp );
5153
52- sb .append (timestamp );
53-
54- for (int i = 0 ; i < 8 ; i ++) {
55- String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
56- sb .append (CHARACTERS .charAt (RANDOM .nextInt (CHARACTERS .length ())));
57- }
54+ for (int i = 0 ; i < 8 ; i ++) {
55+ sb .append (CHARACTERS .charAt (RANDOM .nextInt (CHARACTERS .length ())));
56+ }
5857
59- return sb .toString ();
58+ return sb .toString ();
6059 }
6160
6261 public void deactivate (Long tunnelId ) {
0 commit comments