title: How to set proxy on spring oauth2 OAuth2AccessToken request or How to override OAuth2AccessTokenSupport restTemplate variable?
body: <p>I have tried to set network proxy in the following ways, but none of the method is working</p>
  
  <p>1: set jvm variables like -Dhttp.proxyHost= -Dhttp.proxyPort= .......<br>
  2: Created the Bean.</p>
  
  <pre><code>@Bean
  public RestTemplate restTemplate() {
      final String proxyHost = "######"; // host
      final int proxyPort = ####;  // port
      SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
      factory.setProxy(new Proxy(Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
      return new RestTemplate(factory);
  }
  </code></pre>
  
  <p>But this configuration is overridden by OAuth2AccessTokenSupport.restTemplate.</p>
  
  <p>So the below method always returns the newly created rest template object.</p>
  
  <p>org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport</p>
  
  <pre><code>protected RestOperations getRestTemplate() {
      if (restTemplate == null) {
          synchronized (this) {
              if (restTemplate == null) {
                  RestTemplate restTemplate = new RestTemplate();
                  restTemplate.setErrorHandler(getResponseErrorHandler());
                  restTemplate.setRequestFactory(requestFactory);
                  restTemplate.setInterceptors(interceptors);
                  this.restTemplate = restTemplate;
              }
          }
      }
      if (messageConverters == null) {
          setMessageConverters(new RestTemplate().getMessageConverters());
      }
      return restTemplate;
  }
  </code></pre>
  
  <p>Kindly help me to override or set proxy on the rest template from OAuth Client application.</p>