3434import org .apache .hc .core5 .http .HttpHost ;
3535import org .apache .hc .core5 .http .HttpRequest ;
3636import org .apache .hc .core5 .ssl .SSLContextBuilder ;
37- import org .labkey .remoteapi .security .EnsureLoginCommand ;
3837import org .labkey .remoteapi .security .ImpersonateUserCommand ;
3938import org .labkey .remoteapi .security .LogoutCommand ;
4039import org .labkey .remoteapi .security .StopImpersonatingCommand ;
@@ -225,7 +224,7 @@ public CloseableHttpClient getHttpClient()
225224 }
226225
227226 /**
228- * Create the HttpClientBuilder based on this Connection's configuration options.
227+ * Create the HttpClientBuilder based on this Connection's configuration options and the CredentialsProvider's wishes .
229228 * @return The builder for an HttpClient
230229 */
231230 private HttpClientBuilder clientBuilder ()
@@ -242,6 +241,8 @@ private HttpClientBuilder clientBuilder()
242241 if (null != _userAgent )
243242 builder .setUserAgent (_userAgent );
244243
244+ _credentialsProvider .configureClientBuilder (getBaseURI (), builder );
245+
245246 return builder ;
246247 }
247248
@@ -280,12 +281,11 @@ protected void beforeExecute(HttpRequest request)
280281 {
281282 if (_firstRequest )
282283 {
283- // Make an initial request to ensure login (especially important when invoking @RequiresNoPermission actions),
284- // get a JSESSIONID, and get a CSRF token
285284 try
286285 {
287286 _firstRequest = false ;
288- ensureAuthenticated ();
287+ // First request on this connection: delegate to CredentialsProvider for initialization appropriate to the provider
288+ _credentialsProvider .initializeConnection (this );
289289 }
290290 catch (Exception ignored )
291291 {
@@ -297,7 +297,6 @@ protected void beforeExecute(HttpRequest request)
297297 request .setHeader (JSESSIONID , _sessionId );
298298 }
299299
300-
301300 protected void afterExecute ()
302301 {
303302 // Always update our CSRF token as the session may be new since our last request
@@ -311,15 +310,9 @@ protected void afterExecute()
311310 }
312311 }
313312
314- /**
315- * Ensures that the credentials have been used to authenticate the users and returns a client that can be used for other requests
316- *
317- * @throws IOException if there is an IO problem executing the command to ensure login
318- * @throws CommandException if the server returned a non-success status code.
319- */
313+ @ Deprecated // Not used. Left for backwards compatibility with AccountsManager.updateSiteExpirationBanner(). TODO: Delete!
320314 public void ensureAuthenticated () throws IOException , CommandException
321315 {
322- new EnsureLoginCommand ().execute (this , "/home" );
323316 }
324317
325318 /**
0 commit comments