I use Spring 4 to create a simple application. Recently, I\'m adding Spring Security 3 to the project but always get the Error Code 302 ( so it redirect to home
I believe Spring is redirecting you to /home
because you didn't actually authenticated a User through the login process.
http://mylocal:8080/moon
returning the home.jsp view/acct/signin
) for which you happen to have a mapping with the signin
method in the AccountController
/demo
by returning a String/demo
path is protected (.anyRequest().authenticated()
) to any unauthenticated user, since the current user is indeed unauthenticated, Spring Security will automatically redirect the request to the login page/home
(.loginPage("/home")
)Using a InMemoryUserDetailsManagerConfigurer (see inMemoryAuthentication javadoc), you can only successfully login through the configured credentials. If you want a fully-fledged Authentication system, you must provide an UserDetailsService implementation to your Spring Security configuration (through the userDetailsService method).
EDIT : Following the conversation with chialin.lin, it seems the missing configuration was a defaultSuccessfulUrl for Spring Security to know where to redirect the user once authenticated.