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

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

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

OAuth2RestTemplate.setMessageConverters介绍

暂无

代码示例

代码示例来源: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: spring-projects/spring-security-oauth

@BeforeOAuth2Context
public void fixPaths() {
  init();
  BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) context.getResource();
  List<HttpMessageConverter<?>> converters = new ArrayList<>(context.getRestTemplate().getMessageConverters());
  converters.addAll(getAdditionalConverters());
  context.getRestTemplate().setMessageConverters(converters);
  context.getRestTemplate().setInterceptors(getInterceptors());
  resource.setAccessTokenUri(http.getUrl(tokenPath()));
  if (resource instanceof AbstractRedirectResourceDetails) {
    ((AbstractRedirectResourceDetails) resource).setUserAuthorizationUri(http.getUrl(authorizePath()));
  }
  if (resource instanceof ImplicitResourceDetails) {
    resource.setAccessTokenUri(http.getUrl(authorizePath()));
  }
  if (resource instanceof ResourceOwnerPasswordResourceDetails && !(resource instanceof DoNotOverride)) {
    ((ResourceOwnerPasswordResourceDetails) resource).setUsername(getUsername());
    ((ResourceOwnerPasswordResourceDetails) resource).setPassword(getPassword());
  }
}

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

@Bean
public ResourceOwnerPasswordResourceDetails resource() {
    ResourceOwnerPasswordResourceDetails  r = new ResourceOwnerPasswordResourceDetails ();
    r.setUsername("asdfasdf");
  ....

}
@Bean
public OAuth2RestTemplate restTemplate() {
   OAuth2RestTemplate rest = new OAuth2RestTemplate(resource());
   rest.setMessageConverters(...);
   List<HttpMessageConverter<?>> messageConv = new ArrayList<HttpMessageConverter<?>>();
   messageConv.add(new MappingJackson2HttpMessageConverter());
   rest.setMessageConverters(messageConv);
}

代码示例来源:origin: com.bosch.bis.monitoring/bis-event-publisher-impl

@Bean
@Autowired
public RuntimeDataServiceAddress getRuntimeDataServiceAddress(IntegrationsApiConfig integrationsApiConfig) {
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
  messageConverters.add(new GsonHttpMessageConverter());
  OAuth2RestTemplate oauth2RestTemplate = monitoringServicesConnection.getOauth2RestTemplate();
  oauth2RestTemplate.setMessageConverters(messageConverters);
  URI urlEndpoint = getWebsocketUrlEndpoint(integrationsApiConfig);
  String wsAddress;
  try {
    LOG.info("Use Racoon endpoint to retrieve Websocket address: " + urlEndpoint);
    wsAddress = oauth2RestTemplate.getForObject(urlEndpoint, String.class);
  } catch (HttpStatusCodeException e) {
    String errorMessage = "Failed to retrieve Websocket endpoint address via API Gateway using URL \'"
        + urlEndpoint + "' :" + e.getMessage() + ". Http response: " + e.getResponseBodyAsString();
    LOG.error(errorMessage);
    throw new BisMonitoringFatalException(errorMessage, e);
  }
  LOG.info("Retrieved Websocket address from Racoon: " + wsAddress);
  return new RuntimeDataServiceAddress(wsAddress);
}

代码示例来源:origin: wuxudong/spring-security-oauth2-wechat

wechatTemplate.setMessageConverters(Arrays.asList(customJsonMessageConverter));

相关文章