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

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

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

OAuth2RestTemplate.getResource介绍

暂无

代码示例

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

private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) {
  final AtomicReference<String> confirmationPage = new AtomicReference<String>();
  AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() {
    @Override
    protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() {
      return new ResponseExtractor<ResponseEntity<Void>>() {
        public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
          confirmationPage.set(StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8")));
          return new ResponseEntity<Void>(response.getHeaders(), response.getStatusCode());
        }
      };
    }
  };
  try {
    provider.obtainAuthorizationCode(restTemplate.getResource(), restTemplate.getOAuth2ClientContext().getAccessTokenRequest());
  } catch (UserApprovalRequiredException e) {
    // ignore
  }
  String page = confirmationPage.get();
  verifyAuthorizationPage(page);
}

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

private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) {
  final AtomicReference<String> confirmationPage = new AtomicReference<String>();
  AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() {
    @Override
    protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() {
      return new ResponseExtractor<ResponseEntity<Void>>() {
        public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
          confirmationPage.set(StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8")));
          return new ResponseEntity<Void>(response.getHeaders(), response.getStatusCode());
        }
      };
    }
  };
  try {
    provider.obtainAuthorizationCode(restTemplate.getResource(), restTemplate.getOAuth2ClientContext()
        .getAccessTokenRequest());
  }
  catch (UserApprovalRequiredException e) {
    // ignore
  }
  String page = confirmationPage.get();
  verifyAuthorizationPage(page);
}

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

相关文章