2017-10-05 42 views
0

我正在開發Jersey web服務。在方法之一,我調用WSO2的Identity Server API:https://docs.wso2.com/display/IS530/apidocs/self-registration/#!/operations#SelfRegister#mePost澤西島連接到WSO2的SSL異常

當我嘗試howerver調用它,它返回以下異常:

SunCertPathBuilderException: unable to find valid certification path to requested target 

我正在使用的代碼:

Client restClient = ClientBuilder.newClient(); 
WebTarget webTarget = restClient.target("https://localhost:9443/api/identity/user/v0.9/me"); 

String username = "admin"; 
String separator = ":"; 
String password = "admin"; 
// String passphrase = ""; 

HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); 

restClient.register(feature); 

Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); 
invocationBuilder.header("Authorization", "Basic " + Base64.encodeAsString(username + ":" + password)); 
Response response = invocationBuilder.post(Entity.entity(UserBean.class, MediaType.APPLICATION_JSON)); 

那麼問題在哪裏。我認爲我的身份驗證失敗,從WSO2日誌會支持它,因爲它規定:

Error occurred while trying to authenticate and Authorization header values are not define correctly. 

所以我在debuger的變量檢查標題並將其設置正確,一切都根據文檔。我也發現了這個問題:

Java Certificate Client SSL: unable to find valid certification path to requested target

其中規定,即我的客戶不信任服務器證書,我應該將其導入。好的,但是,我沒有使用Java或Jersey級別的任何密鑰庫,我會在哪裏放置這樣的密鑰庫?另外需要注意的是,Identity Server運行本地的本地主機證書。當我嘗試從瀏覽器進行連接時,它使我無法訪問該網站,可能是因爲客戶端(瀏覽器)不信任證書,因爲它是自簽名的。

回答

1

答案是,從本地WSO2 IS服務器導出證書。你不是有2個選項,你可以

  • 要麼add它的cacerts在JAVA_HOME
  • 或創建明確卡塔利娜truststore和證書導入這些。