【问题标题】:Jersey SSL exception on connect to WSO2连接到 WSO2 时的 Jersey SSL 异常
【发布时间】: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 证书。当我尝试从浏览器连接时,它警告我不要进入该站点,大概是因为客户端(浏览器)不信任证书,因为它是自签名的。

【问题讨论】:

    标签: java rest ssl jersey wso2


    【解决方案1】:

    答案是,从本地 WSO2 IS 服务器导出证书。你有两个选择,你可以

    • add 在 JAVA_HOME 中进行 cacerts
    • 或创建显式 catalina truststore 并将证书导入其中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多