Source:
public RestTemplate jiraAuthenticatedRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); requestFactory.setHttpClient(httpClient); int requestTimeout = DEFAULT_REQUEST_TIMEOUT; String requestTimeoutProperty = env.getProperty("jira.requestTimeoutMillis"); if (!StringUtils.isEmpty(requestTimeoutProperty)) { try { requestTimeout = Integer.parseInt(requestTimeoutProperty); } catch (NumberFormatException ex) { LOGGER.warn("Cannot parse " + requestTimeoutProperty + " as an integer. " + "Using the default value " + DEFAULT_REQUEST_TIMEOUT); requestTimeout = DEFAULT_REQUEST_TIMEOUT; } } requestFactory.setConnectTimeout(requestTimeout); requestFactory.setReadTimeout(requestTimeout); RestTemplate restTemplate = new RestTemplate(requestFactory); restTemplate.getInterceptors().add( new ClientHttpRequestInterceptor() { private String jiraUsername = env.getRequiredProperty("jira.username"); private String jiraPassword = env.getRequiredProperty("jira.password"); @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { String plainCredentials = jiraUsername + ":" + jiraPassword; String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes())); request.getHeaders().add("Authorization", "Basic " + base64Credentials); request.getHeaders().setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); return execution.execute(request, body); } }); return restTemplate; }

Target:
public RestTemplate jiraAuthenticatedRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); requestFactory.setHttpClient(httpClient); int requestTimeout = DEFAULT_REQUEST_TIMEOUT; String requestTimeoutProperty = env.getProperty("jira.requestTimeoutMillis"); if (!StringUtils.isEmpty(requestTimeoutProperty)) { try { requestTimeout = Integer.parseInt(requestTimeoutProperty); } catch (NumberFormatException ex) { LOGGER.warn("Cannot parse " + requestTimeoutProperty + " as an integer. " + "Using the default value " + DEFAULT_REQUEST_TIMEOUT); } } requestFactory.setConnectTimeout(requestTimeout); requestFactory.setReadTimeout(requestTimeout); RestTemplate restTemplate = new RestTemplate(requestFactory); restTemplate.getInterceptors().add( new ClientHttpRequestInterceptor() { private String jiraUsername = env.getRequiredProperty("jira.username"); private String jiraPassword = env.getRequiredProperty("jira.password"); @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { String plainCredentials = jiraUsername + ":" + jiraPassword; String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes())); request.getHeaders().add("Authorization", "Basic " + base64Credentials); request.getHeaders().setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); return execution.execute(request, body); } }); return restTemplate; }