Reputation: 185
It is too simple. If I input the url of /toQuestion in the browser, I will redirect to the page I want successfully. But, by my js code:
window.location.href = "/toQuestion";
I will back to the login page which I configured:
http.authorizeRequests(
authorizeRequests -> authorizeRequests
.mvcMatchers(
"/js/**",
"/css/**",
"/chief",
"/toQuestion").permitAll()
.anyRequest().authenticated()
)
.formLogin(
form -> form
.loginPage("/chief")
.permitAll()
)
Is there any configuration I need to set up?
Upvotes: 0
Views: 209
Reputation: 185
OK.I solved it.Because I didn't implement the supports method of AuthenticationProvider to indicate which Authentication Object this AuthenticationProvider supports.
Upvotes: 0
Reputation: 214
You can change log level of package org.springframework.security to debug and see the reason of redirecting to login page.
Upvotes: 1
Reputation: 379
Looks like you're permiting only authenticated users, that's why it's redirecting. For non user authenticated you must do something like:
...http.authorizeRequests(authorizeRequests -> authorizeRequests
"/toQuestion").permitAll();...
Upvotes: 0