首页 > 解决方案 > 具有安全默认登录成功重定向问题的 Spring Boot

问题描述

我正在使用安全的spring boot,我想要自定义登录页面,成功登录后,我想打开仪表板页面。
在我的代码中,我在成功登录后使用了默认登录页面,它不会重定向到仪表板页面。
我尝试了多种方法,但没有运气。

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    .authorizeRequests()
        .antMatchers("/resources/**", "/register").permitAll()
        .anyRequest().authenticated()
        .and()
        .formLogin().defaultSuccessUrl("/dashboard", true)
//            .loginPage("/login")
        .permitAll()
        .and()
        .logout().logoutSuccessUrl("/login")
        .permitAll();
}
}  

WebMvcConfigurer

@EnableWebMvc
@ComponentScan("com.hrmanagement")
public class WebMvcConfiguration implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {

//    registry.addViewController("/loginPage").setViewName("login");
      registry.addViewController("/dashboard").setViewName("login");
//    registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
}  

在此处输入图像描述 登录成功后重定向到http://localhost:8080/dashboard

我得到
Whitelabel 错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。

Sun Mar 10 17:14:47 IST 2019 出现意外错误(类型=未找到,状态=404)。没有可用的消息。

我试过,在多个位置添加登录页面(静态,模板文件夹,然后添加 webapp-views)但没有运气,任何人都可以建议或帮助我更好地理解。

标签: springspring-bootspring-security

解决方案


推荐阅读