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

标签 spring-security spring-boot spring-java-config

我正在尝试使用Spring Security Java配置保护Web应用程序的安全。

这是配置的样子:-

@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基本身份验证:

.httpBasic().disable()


访问安全的URL时,我仍然收到HTTP Authenticaton提示框。为什么?

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

Spring Boot Starter版本:1.1.5
Spring Security版本:3.2.5

谢谢

最佳答案

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

尝试以下方法:

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

关于spring-security - 使用Spring Security Java配置时禁用基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25639188/

相关文章:

spring-security - 带有 JWT 示例的 Spring Security Jax-rs OAuth2

java - 这相当于在 XML 配置文件中使用 @Autowire 注释 Autowiring 接口(interface)?

java - 从 XML 到 Java 的 Spring 配置不起作用

java - @Autowired 在 Spring-security 中的 UserDetails 上返回异常

java - 创建名称为 '_filterChainProxy' : Initialization of bean failed; nested exception is java. lang.NullPointerException 的 bean 时出错

java - Spring Security SAML,当使用 SAMLContextProviderLB 设置为 HTTPs 方案时重定向到 HTTP 而不是 HTTPS

java - spring data批量保存时如何判断违规实体

java - 如何在Spring Boot Rest模板中使用.pfx证书和密码调用安全的rest api?

Grails 3.3.2 Spring Security CAS 不能通过负载均衡器工作,但可以通过部署在其上的内部服务器正常工作

java - Springboot同步方法