Spring-Boot客户端身份验证配置。

问题描述 投票:1回答:1

首先,我是Spring-Boot和SSL的新手,但是我花了几天的研究时间,基本上是在尝试获取配置了Client Authentication的简单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并获得响应,而无需加载任何类型的客户端证书。 我期望系统提示您输入客户端证书。

ssl spring-boot keystore restful-authentication
1个回答
0
投票

默认情况下,Spring Boot使用tomcat(嵌入式)Web容器。

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

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

 protocol.setClientAuth("need");
© www.soinside.com 2019 - 2024. All rights reserved.