繁体   English   中英

如何从standalone.xml wildfly中读取KeyStore文件路径

[英]How to Read KeyStore File Path From standalone.xml wildfly

首先,如果我的问题无效,我很抱歉,因为我对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;
    }

在上面,您可以看到我已经对.jks文件的路径pathoffile \\ DemoTrust.jks进行了硬编码,还对我的用户名和密码进行了硬编码。

现在,我想从standalone.xml文件中读取所有这些值。 有人可以建议我如何使用Java做到这一点吗?

使用System.getProperty(“ jboss.server.config.dir”)获取配置路径的根。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM