SpringSecurity Basic Authentication

本文详细阐述了如何在非浏览器环境中处理BasicHTTPAuthentication认证,包括认证流程、配置Spring Security的步骤,并指出在遇到AccessDeniedException时,客户端如何响应并重新请求认证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当使用非浏览器处理Basic HTTP Authentication认证时,需post请求携带auth参数即可

Basic HTTP Authentication认证过程
在这里插入图片描述

1.用户访问未授权的private
2.FilterSecurityInterceptor抛出AccessDeniedException
3.ExceptionTranslationFilter开始作用,调用BasicAuthenticationEntryPoint发送WWW-Authenticate header.当客户端收到WWW-Authenticate header,会再次需用户输入username and password

在这里插入图片描述

protected void configure(HttpSecurity http) {
    http
        // ...
        .httpBasic(withDefaults());
}

参考:
https://docs.spring.io/spring-security/site/docs/5.4.5/reference/html5/#servlet-authentication-basic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值