[英]Spring Security Custom Login Error
我一直在尝试将Spring Security Custom Login(Java Config)添加到我的应用程序中,但是一个奇怪的错误不断出现。
我已经完成了创建自定义登录表单教程 ,它工作得很好。 我不确定我的申请是什么问题。
错误
引起:java.lang.IllegalArgumentException:'login?error'不是有效的重定向URL
安全配置
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/about").permitAll();
http
.authorizeRequests()
.antMatchers("/admin","/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("login")
.permitAll();
}
}
的LoginController
@Controller
public class LoginController {
@RequestMapping(value = "login", method = RequestMethod.GET)
public String loginView() {
return "login";
}
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(@ModelAttribute Login login) {
return "home";
}
}
只需注释方法configure(HttpSecurity http)
可以删除异常。 我尝试添加带有值login?error
RequestMapping
login?error
,但它没有帮助。 我在这里错过了什么?
你错过了一个斜线。
这个:
.loginPage("login")
应该:
.loginPage("/login")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.