【发布时间】:2017-10-05 10:09:06
【问题描述】:
我正在开发 Jersey 网络服务。在其中一种方法中,我正在调用 WSO2 身份服务器 API:https://docs.wso2.com/display/IS530/apidocs/self-registration/#!/operations#SelfRegister#mePost
当我尝试调用它时,它返回以下异常:
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.
所以我检查了调试器变量中的标头,它设置正确,一切都根据文档。我也发现了这个问题:
Java Certificate Client SSL: unable to find valid certification path to requested target
其中指出,我的客户端不信任服务器证书,我应该导入它。好的,但是,我没有使用 Java 或 Jersey 级别的任何密钥库,我会将这样的密钥库放在哪里?还要注意,Identity Server 在本地运行 uned localhost 证书。当我尝试从浏览器连接时,它警告我不要进入该站点,大概是因为客户端(浏览器)不信任证书,因为它是自签名的。
【问题讨论】: