org.springframework.security.oauth2.client.OAuth2RestTemplate.setRequestFactory()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.springframework.security.oauth2.client.OAuth2RestTemplate.setRequestFactory()方法的一些代码示例,展示了OAuth2RestTemplate.setRequestFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OAuth2RestTemplate.setRequestFactory()方法的具体详情如下:
包路径:org.springframework.security.oauth2.client.OAuth2RestTemplate
类名称:OAuth2RestTemplate
方法名:setRequestFactory

OAuth2RestTemplate.setRequestFactory介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-security-oauth

private void setupConnectionFactory(OAuth2RestTemplate client) {
  if (Boolean.getBoolean("http.components.enabled")
      && ClassUtils.isPresent("org.apache.http.client.config.RequestConfig",
          null)) {
    client.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {
      @Override
      protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
        HttpClientContext context = HttpClientContext.create();
        context.setRequestConfig(getRequestConfig());
        return context;
      }
      protected RequestConfig getRequestConfig() {
        Builder builder = RequestConfig.custom()
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setAuthenticationEnabled(false).setRedirectsEnabled(false);
        return builder.build();
      }
    });
  }
  else {
    client.setRequestFactory(new SimpleClientHttpRequestFactory() {
      @Override
      protected void prepareConnection(HttpURLConnection connection,
          String httpMethod) throws IOException {
        super.prepareConnection(connection, httpMethod);
        connection.setInstanceFollowRedirects(false);
      }
    });
  }
}

代码示例来源:origin: cloudfoundry/uaa

private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource,
        AccessTokenRequest accessTokenRequest) {
  OAuth2ClientContext context = new DefaultOAuth2ClientContext(accessTokenRequest);
  OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context);
  client.setRequestFactory(new SimpleClientHttpRequestFactory() {
    @Override
    protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
      super.prepareConnection(connection, httpMethod);
      connection.setInstanceFollowRedirects(false);
    }
  });
  client.setErrorHandler(new OAuth2ErrorHandler(client.getResource()) {
    // Pass errors through in response entity for status code analysis
    @Override
    public boolean hasError(ClientHttpResponse response) throws IOException {
      return false;
    }
    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
    }
  });
  List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();
  list.add(new StringHttpMessageConverter());
  list.add(new MappingJackson2HttpMessageConverter());
  client.setMessageConverters(list);
  return client;
}

代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2

private void setupConnectionFactory(OAuth2RestTemplate client) {
  if (Boolean.getBoolean("http.components.enabled")
      && ClassUtils.isPresent("org.apache.http.client.config.RequestConfig",
          null)) {
    client.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {
      @Override
      protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
        HttpClientContext context = HttpClientContext.create();
        context.setRequestConfig(getRequestConfig());
        return context;
      }
      protected RequestConfig getRequestConfig() {
        Builder builder = RequestConfig.custom()
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setAuthenticationEnabled(false).setRedirectsEnabled(false);
        return builder.build();
      }
    });
  }
  else {
    client.setRequestFactory(new SimpleClientHttpRequestFactory() {
      @Override
      protected void prepareConnection(HttpURLConnection connection,
          String httpMethod) throws IOException {
        super.prepareConnection(connection, httpMethod);
        connection.setInstanceFollowRedirects(false);
      }
    });
  }
}

代码示例来源:origin: org.cloudfoundry/cloudfoundry-client-spring

private static void setRequestFactory(OAuth2RestTemplate restTemplate, HostnameVerifier hostnameVerifier, SSLContext sslContext) {
  if (hostnameVerifier != null && sslContext != null) {
    CustomSslSimpleClientHttpRequestFactory requestFactory = new CustomSslSimpleClientHttpRequestFactory(hostnameVerifier, sslContext);
    restTemplate.setRequestFactory(requestFactory);
    restTemplate.setAccessTokenProvider(getAccessTokenProvider(requestFactory));
  }
}

代码示例来源:origin: tigerphz/tgcloud-master

/**
 * O auth 2 rest template o auth 2 rest template.
 *
 * @return the o auth 2 rest template
 */
@Bean("tgcloudOAuth2RestTemplate")
public OAuth2RestTemplate oAuth2RestTemplate() {
  final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails(), new DefaultOAuth2ClientContext());
  oAuth2RestTemplate.setRequestFactory(new Netty4ClientHttpRequestFactory());
  return oAuth2RestTemplate;
}

代码示例来源:origin: stackoverflow.com

protected RestKeyCloakClient()
{
  MultiValueMap<String, String> header = new LinkedMultiValueMap<String, String>();
  OAuth2RestTemplate client;
  DefaultAccessTokenRequest accessTokenRequest = new DefaultAccessTokenRequest();
  DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(accessTokenRequest);
  OAuth2AccessTokenSupport support = new OAuth2AccessTokenSupport()
  {
  };
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
  messageConverters.add(new FormOAuth2AccessTokenMessageConverter());
  messageConverters.add(new FormOAuth2ExceptionHttpMessageConverter());
  MappingJackson2HttpMessageConverter jackson = new MappingJackson2HttpMessageConverter();
  List<MediaType> mediaTypes = new ArrayList<MediaType>();
  mediaTypes.add(new MediaType("application", "x-www-form-urlencoded"));
  jackson.setSupportedMediaTypes(mediaTypes);
  messageConverters.add(jackson);
  support.setMessageConverters(messageConverters);
  client = new OAuth2RestTemplate(getAuthDetails(null, null), context);
  client.setErrorHandler(errorHandler);
  client.setRequestFactory(factory);
  token = client.getAccessToken();
}

代码示例来源:origin: stackoverflow.com

public OAuth2RestTemplate restTemplate() {
  OAuth2RestTemplate template = new OAuth2RestTemplate(oauth2ProtectedResourceDetails(), oauth2ClientContext);
  template.setRequestFactory(httpRequestFactory());
  template.setAccessTokenProvider(accessTokenProvider());
  return template;

相关文章