使用 Spring Security Java 配置时禁用基本身份验证

编程入门 行业动态 更新时间:2024-10-27 10:32:59
本文介绍了使用 Spring Security Java 配置时禁用基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 Spring Security java 配置来保护 Web 应用程序.

I am trying to secure a web application using Spring Security java configuration.

这是配置的样子:-

@Configuration @EnableWebMvcSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private String googleClientSecret; @Autowired private CustomUserService customUserService; /* * (non-Javadoc) * * @see org.springframework.security.config.annotation.web.configuration. * WebSecurityConfigurerAdapter * #configure(org.springframework.security.config * .annotation.web.builders.HttpSecurity) */ @Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off http .authorizeRequests() .antMatchers(HttpMethod.GET, "/","/static/**", "/resources/**","/resources/public/**").permitAll() .anyRequest().authenticated() .and() .formLogin() .and() .httpBasic().disable() .requiresChannel().anyRequest().requiresSecure(); // @formatter:on super.configure(http); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { // @formatter:off auth .eraseCredentials(true) .userDetailsService(customUserService); // @formatter:on super.configure(auth); } }

请注意,我已使用以下方法显式禁用 HTTP 基本身份验证:-

Notice that I have explicitly disabled HTTP Basic authentication using:-

.httpBasic().disable()

在访问安全 URL 时,我仍然收到 HTTP 身份验证提示框.为什么?

I am still getting HTTP Authenticaton prompt box while accessing a secured url. Why?

请帮我解决这个问题.我只想呈现捆绑的默认登录表单.

Please help me fix this. I just want to render the default login form that comes bundled.

Spring Boot 入门版本:1.1.5Spring 安全版本:3.2.5

Spring Boot Starter Version : 1.1.5 Spring Security Version : 3.2.5

谢谢

推荐答案

首先,调用 super.configure(http); 将覆盖你之前的整个配置.

First of all, calling super.configure(http); will override whole your configuration you have before that.

试试这个:

http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .and() .httpBasic().disable();

更多推荐

使用 Spring Security Java 配置时禁用基本身份验证

本文发布于:2023-10-28 20:02:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Spring   Security   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!