spring - 具有安全默认登录成功重定向问题的 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)但没有运气,任何人都可以建议或帮助我更好地理解。
解决方案
推荐阅读
- python - 添加一个新列,其中逐行提取单词
- c# - 在类型上声明的方法不能用类型的实例调用
- keyboard - Dyalog APL 劫持 Windows 密钥并且不将其归还(Fedora 32/Gnome、免费许可证、Kitty)
- python - 从笔记本中的二进制模型中删除 ipynb_checkpoints
- python - ctypes 中 64 位 dll 的持续溢出错误
- amazon-web-services - 许多死亡执行者 EMR
- tabs - 使用 Orchestra/Catel 动态创建选项卡项目和选项卡内容
- python - 使用类创建成绩册 - Python
- jquery - DataTables - 如何为每一行返回特定列的值
- javascript - 为什么我的 nodejs 函数在嵌套函数执行之前返回?