88import uz .server .domain .exception .BaseException ;
99import uz .server .repository .TunnelRepository ;
1010
11+ import java .security .SecureRandom ;
12+ import java .util .Base64 ;
1113import java .util .Optional ;
12- import java .util .UUID ;
1314
1415@ Service
1516@ RequiredArgsConstructor
@@ -27,17 +28,22 @@ public String create(String sessionId, User user) {
2728 }
2829
2930 Tunnel save = repo .save (Tunnel .builder ()
30- .active (true )
3131 .sessionId (sessionId )
32- .subdomain (UUID . randomUUID (). toString ())
32+ .subdomain (getUniqueString ())
3333 .user (user )
3434 .build ());
3535
3636 log .info ("Tunnel created: subdomain={}" , save .getSubdomain ());
3737
3838 return save .getSubdomain ();
3939 }
40-
40+
41+ private static String getUniqueString () {
42+ byte [] randomBytes = new byte [8 ];
43+ new SecureRandom ().nextBytes (randomBytes );
44+ return Base64 .getUrlEncoder ().withoutPadding ().encodeToString (randomBytes );
45+ }
46+
4147 public void deactivate (Long tunnelId ) {
4248 log .info ("Deactivating tunnel: tunnelId={}" , tunnelId );
4349 Optional <Tunnel > tunnel = repo .findById (tunnelId );
@@ -47,12 +53,9 @@ public void deactivate(Long tunnelId) {
4753 throw new BaseException ("Tunnel not found!" );
4854 }
4955
50- Tunnel tunnel1 = tunnel .get ();
51- tunnel1 .setActive (false );
52-
53- log .info ("Tunnel deactivated: tunnelId={}" , tunnelId );
56+ log .info ("Tunnel deactivated and deleting: tunnelId={}" , tunnelId );
5457
55- repo .save ( tunnel1 );
58+ repo .deleteById ( tunnelId );
5659 }
5760
5861 public Tunnel getTunnelBySubdomain (String subdomain ) {
0 commit comments