2017-10-24 2 views
1

다음 HTTP 헤더 인터셉터가있는 스프링 웹 응용 프로그램이 있습니다.org.springframework.ws.transport.http.HttpUrlConnection에서 ssl 인증서를 무시하는 방법

import org.springframework.ws.transport.context.TransportContext; 
import org.springframework.ws.transport.context.TransportContextHolder; 
import org.springframework.ws.transport.http.HttpUrlConnection; 

public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException { 
    TransportContext context = TransportContextHolder.getTransportContext(); 
    HttpUrlConnection connection = (HttpUrlConnection) context 
      .getConnection(); 

    String userCredentials = username + ":" + password; 
    String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes())); 

    connection.getConnection().addRequestProperty("Authorization", basicAuth); 

    return true; 
} 

어떻게하면 SSL 인증서를 무시하도록 코드를 수정할 수 있습니까?

+0

왜 인증서를 무시해야합니까? 그것은 무효/신뢰할 수 있습니까? 아마도 이것은 [Spring RestTemplate으로 SSL 인증서 검사를 비활성화하는 방법] (https://stackoverflow.com/questions/23504819/how-to-disable-ssl-certificate-checking-with-spring-resttemplate)에 도움이 될 것입니다. – pirho

+0

VPN 내에서 액세스 할 수있는 API에 액세스하십시오. 인증서는 존재하지 않았고 컬은 ** - k ** 플래그로 잘 작동했습니다. 코드에서이를 수행하는 방법을 찾고있었습니다 (WebServiceTemplate). –

답변

0

그래서 분명히 해결책을 찾아 냈습니다. 나는 응답을 marshalSendAndReceive하기 위해 WebServiceTemplate을 사용하고 있었다. 여기에 내가 코드에서 무슨 짓을했는지 : -

HttpsUrlConnectionMessageSender sender = new HttpsUrlConnectionMessageSender(); 
sender.setTrustManagers(new TrustManager[] { new UnTrustworthyTrustManager() }); 
webServiceTemplate.setMessageSender(sender); 
response = webServiceTemplate.marshalSendAndReceive(object); 

UnTrustworthyTrustManager 함수 SSL 인증서를 무시 있고 난 오류 PKIX 경로를 건물 없애있어 이것에 의해

class UnTrustworthyTrustManager 
     implements X509TrustManager 
{ 
    public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {} 
    public void checkServerTrusted(X509Certificate[] arg0, String arg1)throws CertificateException {} 
    public X509Certificate[] getAcceptedIssuers() { return null; } 
} 

다음은 실패 : 태양. security.provider.certpath.SunCertPathBuilderException : 요청한 대상에 대한 유효한 인증 경로를 찾을 수 없습니다.

관련 문제