代码之家  ›  专栏  ›  技术社区  ›  chiranjeevigk

Spring引导安全+Spring引导REST存储库配置问题

  •  -1
  • chiranjeevigk  · 技术社区  · 7 年前

    enter image description here Web安全配置为

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().authenticated().and().formLogin();
        }
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            // @formatter:off
            auth.inMemoryAuthentication().withUser("chiru").password("{noop}chiru").roles("ADMIN").and().withUser("user")
                    .password("{noop}user").roles("USER");
            // @formatter:on
        }
    }
    

    我的存储库如下所示

    public interface IssuesRepository extends CrudRepository<Issues, Integer> {
    
    }
    

    enter image description here enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Andrew Sasha    7 年前

    httpBasic() 而不是 formLogin() http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); .

    formLogin()是在您希望使用登录页对用户进行身份验证时使用的(您已经这样做了),但在您的示例中,您使用的是http basic。Spring security无法识别您的http基本头并返回登录页面。

    http.httpBasic().and().formLogin()

    推荐文章