add https

This commit is contained in:
2024-05-15 11:40:22 +08:00
parent d3089a9c4c
commit 84cfa27a5b
93 changed files with 3778 additions and 2340 deletions

View File

@@ -0,0 +1,41 @@
package com.ruoyi.framework.config;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class HttpConnectorConfig {
/**
* 获取Http连接器
* @return Connector
*/
public Connector getHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http"); // 使用http协议
connector.setSecure(false); // 非安全传输
connector.setPort(8080); // HTTP监听端口
connector.setRedirectPort(443); // 重定向端口
return connector;
}
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
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;
}
}

View File

@@ -115,7 +115,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
.antMatchers("/cxxm/version/check**").permitAll()
.antMatchers("/cxxm/app/version/**","/cxxm/app/type/**","/cxxm/app/user/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated()
.and()