首页 > 解决方案 > 春季安全奇怪的重定向

问题描述

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

标签: redirectspring-securityconfiguration

解决方案


推荐阅读