登录后无法重定向spring boot的spring security [英] spring security with spring boot cant redirect after login
本文介绍了登录后无法重定向spring boot的spring security的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在spring boot中集成spring security时遇到问题.覆盖WebSecurityConfigurerAdapter后,访问登录页面时无法重定向到成功页面(wlecome.ftl).(index.ftl) 没有错误日志.
有什么我错过的吗?感谢帮助,谢谢!
<块引用>SecurityConfig.java
@Configuration@启用网络安全@EnableGlobalMethodSecurity(prePostEnabled = true)公共类 SecurityConfig 扩展了 WebSecurityConfigurerAdapter {@自动连线MyUserDetailsService detailsService;@覆盖protected void configure(HttpSecurity http) 抛出异常 {http.authorizeRequests().antMatchers("/user/**").hasRole("USER").anyRequest().fullyAuthenticated().and().formLogin().loginPage("/登录").failureUrl("/login?error=true").usernameParameter("用户名").passwordParameter("密码").defaultSuccessUrl("/user/welcome")//添加这个但是不行.permitAll().and().注销().logoutUrl("/注销").permitAll();}@覆盖公共无效配置(WebSecurity web)抛出异常{web.ignoring().antMatchers("/js/**", "/css/**", "/images/**", "/**/favicon.ico");}@覆盖公共无效配置(AuthenticationManagerBuilder auth)抛出异常{auth.inMemoryAuthentication().withUser("admin").password("admin").roles("USER");}
<块引用>
登录.控制器
@Controller公共类登录控制器{@RequestMapping("/登录")公共字符串登录(){返回索引";}@RequestMapping("/用户/欢迎")公共字符串欢迎(){返回用户/欢迎";}
<块引用>
index.ftl(登录页面)
<#import "/spring.ftl" 作为 spring/><html lang="zh-cn"><头><meta charset="UTF-8"><title>标题</title>头部><身体><form action="<@spring.url '/login'/>"方法=发布">用户名:<input type="text" name="username"><br>密码:
<输入类型=提交"值=登录"></表单>