浏览代码

添加https支持

zhh 6 年之前
父节点
当前提交
69ec434f43

二进制
keystore.p12


+ 21 - 0
mall-portal/src/main/java/com/macro/mall/portal/MallPortalApplication.java

@@ -1,14 +1,35 @@
 package com.macro.mall.portal;
 
+import org.apache.catalina.connector.Connector;
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
+import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
+import org.springframework.context.annotation.Bean;
 
 @SpringBootApplication
 @MapperScan({"com.macro.mall.mapper","com.macro.mall.portal.dao"})
 public class MallPortalApplication {
+    @Value("${http.port}")
+    private Integer port;
 
     public static void main(String[] args) {
         SpringApplication.run(MallPortalApplication.class, args);
     }
+
+    @Bean
+    public EmbeddedServletContainerFactory servletContainer() {
+        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
+        tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
+        return tomcat;
+    }
+
+    //配置http
+    private Connector createStandardConnector() {
+        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
+        connector.setPort(port);
+        return connector;
+    }
 }

+ 6 - 4
mall-portal/src/main/java/com/macro/mall/portal/config/SecurityConfig.java

@@ -62,10 +62,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 .logoutSuccessHandler(new GoLogoutSuccessHandler())
                 .invalidateHttpSession(true)
                 .deleteCookies("JSESSIONID")
-//                .and()
-//                .requiresChannel()
-//                .antMatchers("/sso/*").requiresSecure()
-//                .anyRequest().requiresInsecure()
+                .and()
+                .requiresChannel()
+                .antMatchers("/sso/*")
+                .requiresSecure()
+                .anyRequest()
+                .requiresInsecure()
 //                .and()
 //                .rememberMe()
 //                .tokenValiditySeconds(1800)

+ 6 - 1
mall-portal/src/main/resources/application.properties

@@ -1,5 +1,10 @@
 #===server start===
-server.port=8085
+http.port=8085
+server.port=8443
+server.ssl.key-store=keystore.p12
+server.ssl.key-alias=tomcat
+server.ssl.key-store-password=123456
+server.ssl.key-store-type=PKCS12
 #===server end===
 
 #===logging start===