弹簧安全奇怪的重定向

时间:2021-03-22 08:31:09

标签: redirect spring-security configuration

我有这个 spring 安全配置,控制器就是我展示的那个。它真的很简单...... /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");
}

0 个答案:

没有答案