简体   繁体   English

Spring Boot SSL 已配置,服务器已启动但无法连接到端口

[英]Spring Boot SSL Configured, Server up but not able to connect to Port

I have tried boot application with recent version,wanted to make the rest api ssl secured, I have done below Created the keystore and put into project classpath, the server got started , no problem with starting,but not able to send request 8080 or 8443, below are the configuration,我尝试过使用最新版本的启动应用程序,想让其余的 api ssl 安全,我在下面做了创建密钥库并放入项目类路径,服务器启动,启动没有问题,但无法发送请求 8080 或 8443 , 下面是配置,

server.ssl.key-store=KeyStore.p12 server.ssl.key-store-password=shashank server.ssl.key-alias=mydomain server.ssl.key-password=shashank server.ssl.key-store=KeyStore.p12 server.ssl.key-store-password=shashank server.ssl.key-alias=mydomain server.ssl.key-password=shashank

 @Bean public TomcatServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() { @Override protected void postProcessContext(Context context) { SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.setUserConstraint("CONFIDENTIAL"); SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); securityConstraint.addCollection(collection); context.addConstraint(securityConstraint); } }; tomcat.addAdditionalTomcatConnectors(getHttpConnector()); return tomcat; } private Connector getHttpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("https"); connector.setPort(8080); connector.setSecure(true); connector.setRedirectPort(8443); }

INFO 84898 --- [ main] osbwembedded.tomcat.TomcatWebServer : Tomcat started on port(s): enter image description here 8443 (https) 8080 (https) with context path '/event-processing'信息 84898 --- [主要] osbwembedded.tomcat.TomcatWebServer : Tomcat 在端口上启动:在此处输入图像描述8443 (https) 8080 (https) 和上下文路径“/事件处理”

as this is self signed certificate, it says " this certificate is not verfied from third party"由于这是自签名证书,因此显示“此证书未从第三方验证”

The intention is here is to make https to all rest api's enter image description here这里的目的是让所有rest api的https进入这里图像描述

Try out these changes :尝试这些更改:

Modify application.properties to edit server.ssl.key-store parameter value to keystore.p12 from KeyStore.p12修改application.properties以将server.ssl.key-store参数值从KeyStore.p12编辑为keystore.p12

server.ssl.key-store: keystore.p12

Add the TomcatEmbeddedServletContainerFactory bean to @Configuration class (any one).将 TomcatEmbeddedServletContainerFactory bean 添加到@Configuration 类(任何一个)。

 @Bean
  public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
          SecurityConstraint securityConstraint = new SecurityConstraint();
          securityConstraint.setUserConstraint("CONFIDENTIAL");
          SecurityCollection collection = new SecurityCollection();
          collection.addPattern("/*");
          securityConstraint.addCollection(collection);
          context.addConstraint(securityConstraint);
        }
      };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
  }

  private Connector initiateHttpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setPort(8080);
    connector.setSecure(false);
    connector.setRedirectPort(8443);

    return connector;
  }

我使用自签名证书遇到了这个问题,并通过在服务器计算机而不是我的本地计算机中创建证书来解决它,因此您应该运行在服务器计算机中创建证书的 keytool 命令并使用 .p12 生成的文件您的项目和一切都会按预期进行。

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

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