redirect - 春季安全奇怪的重定向
问题描述
我有这个弹簧安全配置,控制器就是我展示的那个。它真的很简单...... /form 加载表单,其他的 JSP 只加载带有文件名之类的字符串的页面。我有一个我以前没有经历过的奇怪行为,比如:如果我点击 http://localhost:1111/preferences,它会重定向到 /form,但它会显示 404。我昨天遇到的其他情况是我正确登录(至少在代码级别),但它重定向到 /home 但不显示正确的屏幕。]有谁知道这是怎么回事?
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/form").permitAll()
.antMatchers("/history").hasAuthority("EMPLOYEE")
.antMatchers("/home").hasAuthority("EMPLOYEE")
.antMatchers("/live").hasAuthority("EMPLOYEE")
.antMatchers("/management").hasAnyAuthority("ADMIN")
.antMatchers("/preferences").hasAuthority("EMPLOYEE")
.antMatchers("/api/**").hasAuthority("EMPLOYEE")
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/form")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/home", true)
.usernameParameter("username")
.passwordParameter("password")
.failureHandler(new CustomAuthenticationFailureHandler());
}
和
@GetMapping(value = {"/form"})
public ModelAndView login() {
return new ModelAndView("form");
}
@GetMapping(value = {"/history"})
public ModelAndView history() {
return new ModelAndView("history");
}
@GetMapping(value = {"/home"})
public ModelAndView home() {
return new ModelAndView("home");
}
@GetMapping(value = {"/live"})
public ModelAndView live() {
return new ModelAndView("live");
}
@GetMapping(value = {"/management"})
public ModelAndView management() {
return new ModelAndView("management");
}
@GetMapping(value = {"/preferences"})
public ModelAndView preferences() {
return new ModelAndView("preferences");
}
解决方案
推荐阅读
- android - ConstraintLayout 用 app:layout_constrainedHeight="true" 隐藏 TextView 的最后一行
- javascript - 在 React Final Form 中通过 API 调用动态填充 Select 选项
- blogger - Blogger 最低要求
- javafx - 如何在 javafx 中使用 GridPane 制作圆形的金字塔图案
- r - 使用动态变量名称从 R 调用系统命令
- python - Django admin继承,在父模型中引用子模型id
- vue.js - Vue上拖一个玩家名字,拖整个列表
- html - 我想在 html 中的视频播放器周围放置边框
- mongodb - kafka mongo db 源连接器与在 kubernetes 上运行的 mongo db
- javascript - JQuery 属性切换解决方法?