首页 > 其他分享 >SpringBoot基于Spring Security的HTTP跳转HTTPS

SpringBoot基于Spring Security的HTTP跳转HTTPS

时间:2023-07-24 16:13:37浏览次数:51  
标签:HTTP SpringBoot 跳转 springframework org import security annotation

简单说说

之所以采用Spring Security来做这件事,一是Spring Security可以根据不同的URL来进行判断是否需要跳转(不推荐),

二是不需要新建一个TomcatServletWebServerFactory Bean,新建这个Bean可能会导致SpringBoot关于Server的配置失效。

三是网上大部分流传的通过实现WebServerFactoryCustomizer来自定义跳转,在我的项目中一直没能生效。

 

代码也很简单

package com.github.codeactions.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

/**
 * SecurityConfiguration
 *
 * @author hackyo
 * @since 2022/4/1
 */
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfiguration {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.portMapper(portMapper -> portMapper.http(80).mapsTo(443))
                .requiresChannel(requiresChannel -> requiresChannel.anyRequest().requiresSecure());
        return http.build();
    }

}

 

标签:HTTP,SpringBoot,跳转,springframework,org,import,security,annotation
From: https://www.cnblogs.com/hackyo/p/17577489.html

相关文章

  • SpringBoot+Vue实现校园二手系统。前后端分离技术【完整功能介绍+实现详情+源码】
    前言       这个系统基本上可以改造为其它类似的系统。后台管理基本上一致。前台进行一些页面样式的改造就可以变成一个新的系统。有时间,做几个变体系统。       闲的无聊,把大学时候做的一个系统进行了重构。将项目拆分成完全前后端分离的形式。客户端采用一套、商家......
  • SpringBoot集成日志入门
    一、日志的作用程序中的日志是记录程序的运行情况,包括用户的各种操作、程序的运行状态等信息。类似于飞机的黑匣子。二、日志的级别表:日志级别及其描述日志级别描述OFF关闭:不输出日志FATAL致命:用于输出可能会导致应用程序终止的错误ERROR错误:用于输出程序的错误(这些错误不会导......
  • SpringBoot源码第四章-invokeBeanFactoryPostProcessors
    invokeBeanFactoryPostProcessors()实例化和调用所有BeanFactoryPostProcessorprotectedvoidinvokeBeanFactoryPostProcessors(ConfigurableListableBeanFactorybeanFactory){ PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory,getBeanFa......
  • 【遇到一个神奇的问题】暂未想到原因,http.Post 传入 nil参数正确,但是传输值为 nil 的
    出错的代码如下:funcgetEab(ctxcontext.Context,credentialsJSONstring,old*externalAccountKeyResp)(*externalAccountKeyResp,error){//inithttpclient// varpostData*bytes.Reader=nil ifold!=nil{ buf,_:=json.Marshal(old) postData......
  • SpringBoot源码第三章-refreshContext
    refreshContext()刷新上下文privatevoidrefreshContext(ConfigurableApplicationContextcontext){/***cintext=AnnotationConfigApplicationContext*/refresh(context);if(this.registerShutdownHook){ try{ context.registerShu......
  • Dubbo Triple 协议重磅升级:支持通过 HTTP 连通 Web 与后端微服务
    作者:刘军全新升级的Triple协议在微服务协议选型方面我们看到越来越多的应用从Dubbo2TCP二进制协议迁移到Dubbo3Triple协议(兼容gRPC),以充分利用Triple的高效、全双工、Streaming流式通信模型等能力;Triple+HTTP/2的组合很好的解决了后端服务穿透性等问题,但在阿里及......
  • 好奇-->springboot启动时候的机制
    问题一:springboot启动的组件顺序?问题二:启动的组件大致分为哪几种?是干嘛的?埋下伏笔,明日解决-->2023-07-24 ......
  • springboot获取ApplicationContext的两种方式
    方法1:启动类返回的就是个ApplicationContext对象,可以把这个对象存在当前类的静态变量中;方法2:写个工具类,实现ApplicationContextAware接口,实现默认方法setApplicationContext,传入的参数即applicationContext,找个地方存放即可......
  • Springboot 整合mybatis 加导出excel
    快速写一个springboot,mybatis的demo,最后用excel导出。第一步,创建一个新maven命名就按自己的来啦第二步,配置pom文件<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version&g......
  • SpringBoot自动化装配中,如何解决组件装配顺序
    SpringBoot自动化装配中,如果有两个AutoConfiguration,A依赖B,这时ConditionalOnBean如何保证顺序使需要的Bean会提前加载使用@AutoConfigureAfter,当几个组件加载完成后,再加载当前组件,如:Nacos服务注册自动配置类加载前需要加载:通用的服务注册配置,服务注册的自动化配置,服务发现的自......