【问题标题】:Spring-Boot client authentication configuration.Spring-Boot 客户端身份验证配置。
【发布时间】:2015-06-20 12:08:53
【问题描述】:

首先,我是 Spring-Boot 和 SSL 的新手,但我花了几天时间研究,基本上是想获得一个配置了客户端身份验证的简单 Spring-Boot 应用程序。

我已经像这样设置了一个连接器:

private Connector createSslConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    try {
        File keystore = getKeyStoreFile();
        File truststore = keystore;
        connector.setScheme("https");
        connector.setSecure(true);
        connector.setPort(sslPort);
        protocol.setSSLEnabled(true);
        protocol.setKeystoreFile(keystore.getAbsolutePath());
        protocol.setKeystorePass("changeit");
        protocol.setTruststoreFile(truststore.getAbsolutePath());
        protocol.setTruststorePass("changeit");
        protocol.setKeyAlias("apitester");
        protocol.setClientAuth("need");
        return connector;
    }
    catch (IOException ex) {
        throw new IllegalStateException("cant access keystore: [" + "keystore"
                + "] or truststore: [" + "keystore" + "]", ex);
    }
}

还有一个看起来像这样的控制器:

@RequestMapping("/test/{identifier}")
@ResponseBody
ResponseEntity<String> test(HttpServletRequest request, @PathVariable String identifier) {
    return new ResponseEntity<String>("hello: " + identifier, HttpStatus.OK)
}

但是,一旦我启动我的应用程序,我就可以使用浏览器导航到 localhost:sslport/hello/test/xxxx 并获得响应,而无需加载任何类型的客户端证书。我期待被提示输入客户端证书。

【问题讨论】:

  • 你试过https://localhost:sslport/hello/test/xxxx吗?

标签: ssl spring-boot keystore restful-authentication


【解决方案1】:

Spring boot 默认使用 tomcat(嵌入式)web 容器。

因为它被称为tomcat doc,我们必须将其设置为 true 以在接受连接之前强制从客户端传播有效证书链。设置 want 将允许客户端提供证书,但不是绝对必需的。

我怀疑“需要”对容器是否有意义。

 protocol.setClientAuth("need");

【讨论】:

    猜你喜欢
    • 2017-02-04
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2013-07-20
    • 2018-01-29
    • 2019-07-30
    • 2018-09-16
    • 2018-06-15
    相关资源
    最近更新 更多