首先,如果我的问题无效,我很抱歉,因为我对 SSL 实现和验证来自受信任证书颁发机构的请求一无所知。
基本上,我们使用 .jks 文件来验证请求,并且使用部署在 wildfly 上的 JAX-RS。
在standalone.xml中我们完成了如下配置:
<management>
<security-realms>
**<security-realm name="SslRealm">
<server-identities>
<ssl>
<keystore path="../../../ssl/keystore.jks" relative-to="jboss.server.config.dir" keystore-password="changeme"/>
</ssl>
</server-identities>
</security-realm>**
</security-realms>
现在在java代码中我们需要读取.jks文件、用户名和密码:
public static Response getArtifactsHttps(String authInfo, String area) {
String username = "username";
String password1 = "password";
StringBuilder authorization = new StringBuilder();
authorization.append(username).append(":").append(password1);
// String authHeader = "Basic " + Base64.getEncoder().encodeToString(authorization.toString().getBytes());
Response response = RestAssured
.given()
.keyStore("pathOffile\\DemoTrust.jks", "DemoTrustKeyStorePassPhrase")
.when()
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.header(Constant.HTTP_HEADERS.AUTHORIZATION, "Basic " + authInfo)
.header(Constant.HTTP_HEADERS.MODULETYPE, Constant.AC_MODULETYPE.CLIENT)
.get("login").thenReturn();
System.out.println("RESPONSE" + response);
return response;
}
In the above you can see i have hardcoded the path of the .jks file pathoffile\DemoTrust.jks also username and password i have hardcoded.
现在我想从standalone.xml 文件中读取所有这些值。有人可以建议我如何使用 java 来做到这一点吗?
最佳答案
使用 System.getProperty("jboss.server.config.dir") 获取配置路径的根目录。
关于java - 如何从standalone.xml 中读取KeyStore 文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47627813/