mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix TomcatEngine to support https
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.dromara.hutool.http.server;
|
||||
|
||||
import org.dromara.hutool.core.net.ssl.SSLContextUtil;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.security.KeyStore;
|
||||
|
||||
/**
|
||||
* 服务器配置
|
||||
@@ -115,6 +118,18 @@ public class ServerConfig {
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置证书库<br>
|
||||
* 此方法和{@link #setSslContext(SSLContext)}互斥
|
||||
*
|
||||
* @param keyStore 证书库
|
||||
* @param passwd 密码
|
||||
* @return this
|
||||
*/
|
||||
public ServerConfig setKeystore(final KeyStore keyStore, final char[] passwd) {
|
||||
return setSslContext(SSLContextUtil.createSSLContext(keyStore, passwd));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置SSL上下文
|
||||
*
|
||||
|
@@ -125,20 +125,34 @@ public class TomcatEngine extends AbstractServerEngine {
|
||||
// SSL配置
|
||||
final SSLContext sslContext = config.getSslContext();
|
||||
if(null != sslContext){
|
||||
final SSLHostConfig sslHostConfig = new SSLHostConfig();
|
||||
final SSLHostConfigCertificate sslHostConfigCertificate =
|
||||
new SSLHostConfigCertificate(sslHostConfig, SSLHostConfigCertificate.Type.RSA);
|
||||
sslHostConfigCertificate.setSslContext(new JSSESSLContext(sslContext));
|
||||
sslHostConfig.addCertificate(sslHostConfigCertificate);
|
||||
connector.addSslHostConfig(sslHostConfig);
|
||||
protocol.setSSLEnabled(true);
|
||||
protocol.setSecure(true);
|
||||
protocol.addSslHostConfig(createSSLHostConfig(sslContext));
|
||||
|
||||
connector.setScheme("https");
|
||||
connector.setSecure(true);
|
||||
connector.setPort(config.getPort());
|
||||
}
|
||||
|
||||
return connector;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建SSL HostConfig
|
||||
*
|
||||
* @param sslContext SSLContext
|
||||
* @return SSL HostConfig
|
||||
*/
|
||||
private static SSLHostConfig createSSLHostConfig(final SSLContext sslContext) {
|
||||
final SSLHostConfig sslHostConfig = new SSLHostConfig();
|
||||
|
||||
final SSLHostConfigCertificate sslHostConfigCertificate =
|
||||
new SSLHostConfigCertificate(sslHostConfig, SSLHostConfigCertificate.Type.RSA);
|
||||
sslHostConfigCertificate.setSslContext(new JSSESSLContext(sslContext));
|
||||
|
||||
sslHostConfig.addCertificate(sslHostConfigCertificate);
|
||||
return sslHostConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化Context
|
||||
*
|
||||
|
Reference in New Issue
Block a user