连接到 WSO2 时泽西岛 SSL 异常
Jersey SSL exception on connect to WSO2
我正在开发 Jersey Web 服务。在其中一种方法中,我正在调用 WSO2 身份服务器 API:https://docs.wso2.com/display/IS530/apidocs/self-registration/#!/operations#SelfRegister#mePost
然而,当我尝试调用它时,它 returns 出现以下异常:
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.
所以我检查了调试器变量中的header,它设置正确,一切都是根据文档。我也发现了这个问题:
也就是说,我的客户不信任服务器证书,我应该导入它。好的,但是,我没有在 Java 或 Jersey 级别上使用任何密钥库,我应该把这样的密钥库放在哪里?还要注意,Identity Server 在本地运行未使用本地主机证书。当我尝试从浏览器连接时,它让我无法进入该站点,大概是因为客户端(浏览器)不信任证书 self-signed.
答案是,从本地 WSO2 IS 服务器导出证书。你有 2 个选择,你可以
- 要么 add 它到 JAVA_HOME
中的 cacerts
- 或创建明确的 catalina truststore 并将证书导入其中。
我正在开发 Jersey Web 服务。在其中一种方法中,我正在调用 WSO2 身份服务器 API:https://docs.wso2.com/display/IS530/apidocs/self-registration/#!/operations#SelfRegister#mePost
然而,当我尝试调用它时,它 returns 出现以下异常:
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.
所以我检查了调试器变量中的header,它设置正确,一切都是根据文档。我也发现了这个问题:
也就是说,我的客户不信任服务器证书,我应该导入它。好的,但是,我没有在 Java 或 Jersey 级别上使用任何密钥库,我应该把这样的密钥库放在哪里?还要注意,Identity Server 在本地运行未使用本地主机证书。当我尝试从浏览器连接时,它让我无法进入该站点,大概是因为客户端(浏览器)不信任证书 self-signed.
答案是,从本地 WSO2 IS 服务器导出证书。你有 2 个选择,你可以
- 要么 add 它到 JAVA_HOME 中的 cacerts
- 或创建明确的 catalina truststore 并将证书导入其中。