Spring Boot WebSecurityConfigurerAdapter - 如果输入登录URL,则重定向

时间:2018-05-02 07:12:50

标签: spring spring-mvc spring-boot

我有我的WebSecurityConfigurerAdapter configure()方法

http.authorizeRequests().antMatchers("/static/**").permitAll().anyRequest().authenticated().and()
                    .formLogin().loginPage("/login")
                    // Redirection after login
                    .defaultSuccessUrl("/home", true).permitAll().and().logout()
                    // logout link. Check if there is no conflict with SAML
                    .logoutRequestMatcher(new AntPathRequestMatcher("/saml/logout")).deleteCookies("JSESSIONID")
                    .invalidateHttpSession(true).logoutSuccessUrl("/").permitAll();

如果用户尝试访问/home,如何将登录用户重定向到/login

PS - 我的控制器代码

@RequestMapping(method = RequestMethod.GET, value = {"/login"})
public String getIndexPage() {
    return LOGIN_PAGE;
}

@RequestMapping(method = RequestMethod.GET, value = {"/"})
public String getHomePage() {
    return "redirect:/home";
}

0 个答案:

没有答案