关于Spring security 使用时禁用自带的登录页面

寻找了一天的方法,都不能解决这个问题。
后来自己试了试不实用表单登录,发现可以了。

找到的几个解决办法:
https://www.zhangbj.com/p/524.html

https://www.baeldung.com/spring-boot-security-autoconfiguration

表单登录时 loginPage方法的原理:
https://stackoverflow.com/questions/28658265/how-to-remove-a-filter-from-spring-security
(这就是为什么当自定义页面后,不会出现spring security自带的页面)
可以去看看这个类,了解原理:

public abstract class AbstractAuthenticationFilterConfigurer<B  extends HttpSecurityBuilder<B>,T extends AbstractAuthenticationFilterConfigurer<B,T, F>, F extends AbstractAuthenticationProcessingFilter> extends AbstractHttpConfigurer<B> 

我的解决办法:

//                securityhttp.and()
//                .formLogin(); // Use form login

删掉了表单登录。

其实在spring boot 项目启动时,控制台可以看到当前FilterChain的顺序。
里面有三个filter:

org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter
org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter

有这三个filter就会出现自带的登录页面。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值