从spring迁移到spring引导(spring安全验证不工作)

snvhrwxg  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(421)
@Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().and().headers().and().anonymous().disable()
                    .formLogin().loginPage("/login.html").failureHandler(this.authenticationFailureHandler)
                    .defaultSuccessUrl("/main").loginProcessingUrl("/j_spring_security_check")
                    .usernameParameter("j_username").passwordParameter("j_password")
                    .and()
                    .logout().logoutUrl("/j_spring_security_logout").logoutSuccessUrl("/login.html");
}

当我点击登录按钮时,它会将我重定向到

7bsow1i6

7bsow1i61#

将其添加到安全配置类中。authorizerequests().antmatchers(“/login*”).permitall()
删除以下和().headers()和().anonymous()

@Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable()
                    .formLogin().loginPage("/login.html").failureHandler(this.authenticationFailureHandler)
                    .defaultSuccessUrl("/main").loginProcessingUrl("/j_spring_security_check")
                    .usernameParameter("j_username").passwordParameter("j_password")
                    .and()
                    .logout().logoutUrl("/j_spring_security_logout").logoutSuccessUrl("/login.html");
}

相关问题