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

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

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

OAuth2RestTemplate.setErrorHandler介绍

暂无

代码示例

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

public OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context) {
  super();
  if (resource == null) {
    throw new IllegalArgumentException("An OAuth2 resource must be supplied.");
  }
  this.resource = resource;
  this.context = context;
  setErrorHandler(new OAuth2ErrorHandler(resource));
}

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

private OAuth2RestTemplate createRestTemplate(
    OAuth2ProtectedResourceDetails resource, AccessTokenRequest request) {
  OAuth2ClientContext context = new DefaultOAuth2ClientContext(request);
  OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context);
  setupConnectionFactory(client);
  client.setErrorHandler(new DefaultResponseErrorHandler() {
    // Pass errors through in response entity for status code analysis
    public boolean hasError(ClientHttpResponse response) throws IOException {
      return false;
    }
  });
  if (accessTokenProvider != null) {
    client.setAccessTokenProvider(accessTokenProvider);
  }
  return client;
}

代码示例来源: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: cloudfoundry/uaa

if (restTemplate instanceof OAuth2RestTemplate) {
  OAuth2RestTemplate oAuth2RestTemplate = (OAuth2RestTemplate)restTemplate;
  oAuth2RestTemplate.setErrorHandler(new UaaOauth2ErrorHandler(oAuth2RestTemplate.getResource(), HttpStatus.Series.SERVER_ERROR));
} else {
  restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {

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

public OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context) {
  super();
  if (resource == null) {
    throw new IllegalArgumentException("An OAuth2 resource must be supplied.");
  }
  this.resource = resource;
  this.context = context;
  setErrorHandler(new OAuth2ErrorHandler(resource));
}

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

@Configuration
public class OverridenConfiguration {
  @Autowire
  private OAuth2RestTemplate restTemplate;

  @PostConstruct
  public void customSettings() {
    System.out.println("************** custom settings ***********");
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
      @Override
      public void handleError(ClientHttpResponse response) throws IOException {
        // do some stuff
      }
    });
  }
}

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

private OAuth2RestTemplate createRestTemplate(
    OAuth2ProtectedResourceDetails resource, AccessTokenRequest request) {
  OAuth2ClientContext context = new DefaultOAuth2ClientContext(request);
  OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context);
  setupConnectionFactory(client);
  client.setErrorHandler(new DefaultResponseErrorHandler() {
    // Pass errors through in response entity for status code analysis
    public boolean hasError(ClientHttpResponse response) throws IOException {
      return false;
    }
  });
  if (accessTokenProvider != null) {
    client.setAccessTokenProvider(accessTokenProvider);
  }
  return client;
}

代码示例来源: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();
}

相关文章