Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HttpSecurity配置-允许所有仍然需要基本的身份验证_Java_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Java HttpSecurity配置-允许所有仍然需要基本的身份验证

Java HttpSecurity配置-允许所有仍然需要基本的身份验证,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我正试图将一个不安全的控制器端点/foo/bar添加到我的应用程序中,但每当我尝试调用它时,就会得到401个未经授权的 这是我的网站安全配置适配器: http .authorizeRequests() .antMatchers("/foo/**").permitAll() .and() .formLogin() .loginPage("/login").permitAll() .and() .requestMatchers(

我正试图将一个不安全的控制器端点
/foo/bar
添加到我的应用程序中,但每当我尝试调用它时,就会得到
401个未经授权的

这是我的
网站安全配置适配器

http
    .authorizeRequests()
        .antMatchers("/foo/**").permitAll()
    .and()
    .formLogin()
        .loginPage("/login").permitAll()
    .and()
    .requestMatchers()
        .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
    .and()
    .authorizeRequests()
        .anyRequest().authenticated();

有人能指出我遗漏了什么吗?

在一个
authorizeRequests
部分中连接多个
antMatchers

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
                .antMatchers("/foo/**").permitAll()
                .anyRequest().authenticated()
            .and()
            .formLogin().loginPage("/login").permitAll();
}

我不确定您的
配置中的
层次结构是什么,但它似乎不正确

尝试:


/GET或POST应该允许foo/bar,或者两者都允许?@Sanj它不应该与身份验证机制有关,方法由RequestMapping过滤掉
http
    .formLogin()
        .loginPage("/login")
        .and()
    .authorizeRequests()
        .antMatchers("/foo/**").permitAll()
        .anyRequest().authenticated();