[英]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.