Access HTTPS RESTful service using Web Client in Spring Boot 2.0 throwing exception

前端 未结 1 1147
终归单人心
终归单人心 2021-01-22 01:32

I have to access one https rest web service(https://example.com) for which certificate has been provided by the client which contains 2 .cer files.

I have created

相关标签:
1条回答
  • 2021-01-22 02:27

    I had a similar problem:

    @Bean("oAuth2")
    public WebClient webOAuth2Client(ReactiveClientRegistrationRepository registration,
                               ServerOAuth2AuthorizedClientRepository clientRepository) {
    
        ServerOAuth2AuthorizedClientExchangeFilterFunction filter =
                new ServerOAuth2AuthorizedClientExchangeFilterFunction(
                        registration,
                        clientRepository);
        filter.setDefaultClientRegistrationId("oAuth2");
       
    
        return WebClient
                .builder()
                .filter(filter)
                .build();
    }
    

    in property file something like:

        security:
        oauth2:
          client:
            provider:
              oAuth2:
                token-uri: url:port/auth/realms/SCRealm/protocol/openid-connect/token
            registration:
              oAuth2:
                clientId: client_id
                clientSecret: client_secret
                authorizationGrantType: client_credentials
                clientAuthenticationMethod: post
    

    And in main application class :

    System.setProperty("-Dio.netty.handler.ssl.noOpenSsl","true");
    System.setProperty("javax.net.ssl.trustStore", "keyStore.jks");
    System.setProperty("javax.net.ssl.trustStoreType", "JKS");
    System.setProperty("javax.net.ssl.trustStorePassword", "any_strong_pass");
    
    0 讨论(0)
提交回复
热议问题