2121import java .util .Map ;
2222import java .util .concurrent .Callable ;
2323import java .util .concurrent .CountDownLatch ;
24+ import java .util .concurrent .TimeUnit ;
2425import okhttp3 .Call ;
2526import okhttp3 .Callback ;
2627import okhttp3 .Response ;
@@ -43,7 +44,8 @@ public class AsyncRequestCallable implements Callable<String>, Callback
4344 final String [] callbackResult = {null };
4445 private CountDownLatch latch ;
4546
46- public AsyncRequestCallable (PrivacyIDEA privacyIDEA , Endpoint endpoint , String path , Map <String , String > params , Map <String , String > headers , boolean authTokenRequired , String method )
47+ public AsyncRequestCallable (PrivacyIDEA privacyIDEA , Endpoint endpoint , String path , Map <String , String > params ,
48+ Map <String , String > headers , boolean authTokenRequired , String method )
4749 {
4850 this .privacyIDEA = privacyIDEA ;
4951 this .endpoint = endpoint ;
@@ -69,7 +71,11 @@ public String call() throws Exception
6971 String tmpPath = path ;
7072 path = ENDPOINT_AUTH ;
7173 endpoint .sendRequestAsync (ENDPOINT_AUTH , privacyIDEA .serviceAccountParam (), Collections .emptyMap (), PIConstants .POST , this );
72- latch .await ();
74+ if (!latch .await (30 , TimeUnit .SECONDS ))
75+ {
76+ privacyIDEA .error ("Latch timed out..." );
77+ return "" ;
78+ }
7379 // Extract the auth token from the response
7480 String response = callbackResult [0 ];
7581 String authToken = privacyIDEA .parser .extractAuthToken (response );
@@ -87,7 +93,11 @@ public String call() throws Exception
8793 // Do the actual request
8894 latch = new CountDownLatch (1 );
8995 endpoint .sendRequestAsync (path , params , headers , method , this );
90- latch .await ();
96+ if (!latch .await (30 , TimeUnit .SECONDS ))
97+ {
98+ privacyIDEA .error ("Latch timed out..." );
99+ return "" ;
100+ }
91101 return callbackResult [0 ];
92102 }
93103
0 commit comments