【问题标题】:Configure SpringBoot security with Vue使用 Vue 配置 Spring Boot 安全性
【发布时间】:2018-06-09 10:09:08
【问题描述】:

我试图配置一个 spring 安全性以与 Rest 一起使用,所以我创建了这个文件:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private UserDetailsService userDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().
                csrf().disable().
                authorizeRequests()
                .antMatchers("/home").permitAll()
                .antMatchers(HttpMethod.POST, "/login").permitAll()
                .anyRequest().authenticated()
                .and().formLogin().loginProcessingUrl("/login").failureForwardUrl("/login?erro")
                .and().logout().logoutUrl("/logout")
                .and().httpBasic().disable();

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticationProvider());
    }

    @Bean
    public DaoAuthenticationProvider authenticationProvider() {
        DaoAuthenticationProvider authProvider
                = new DaoAuthenticationProvider();
        authProvider.setUserDetailsService(userDetailsService);
        authProvider.setPasswordEncoder(encoder());
        return authProvider;
    }

    @Bean
    public PasswordEncoder encoder() {
        return new BCryptPasswordEncoder(11);
    }
}

但是当我尝试使用错误的密码和用户名访问 /login 时,尝试重定向到默认表单登录。

如何禁用此默认表单?

tks

【问题讨论】:

    标签: spring-boot spring-security


    【解决方案1】:

    可以使用自定义登录的配置

     .and()
    .formLogin()
    .loginPage("/login");
    

    这一行 loginPage("/login") 将告诉 spring security 覆盖默认登录页面

    结帐this

    【讨论】:

      猜你喜欢
      • 2014-10-27
      • 2014-02-05
      • 2014-07-19
      • 1970-01-01
      • 2019-01-02
      • 2018-10-07
      • 1970-01-01
      • 2019-08-25
      相关资源
      最近更新 更多