/** * Execute request either as is or under PrivilegedAction * if a Subject is available for url * @param httpClient the {@link CloseableHttpClient} to be used to execute the httpRequest * @param httpRequest the {@link HttpRequest} to be executed * @param localContext th {@link HttpContext} to be used for execution * @param url the target url (will be used to look up a possible subject for the execution) * @return the result of the execution of the httpRequest * @throws IOException */ private CloseableHttpResponse executeRequest(final CloseableHttpClient httpClient, final HttpRequestBase httpRequest, final HttpContext localContext, final URL url) throws IOException { AuthManager authManager = getAuthManager(); if (authManager != null) { Subject subject = authManager.getSubjectForUrl(url); if (subject != null) { try { return Subject.doAs(subject, (PrivilegedExceptionAction<CloseableHttpResponse>) () -> httpClient.execute(httpRequest, localContext)); } catch (PrivilegedActionException e) { log.error("Can't execute httpRequest with subject: {}", subject, e); throw new RuntimeException("Can't execute httpRequest with subject:" + subject, e); } } } return httpClient.execute(httpRequest, localContext); }
HttpContext localContext = new BasicHttpContext(); HttpClientContext clientContext = HttpClientContext.adapt(localContext); clientContext.setAttribute(CONTEXT_ATTRIBUTE_AUTH_MANAGER, getAuthManager()); try { httpClient = setupClient(jMeterVariables, url, clientContext);