By default, spring security after authentication redirects you to protected page you tried to access before.
When I implement my own success handler
@Component
class MyS: AuthenticationSuccessHandler {
override fun onAuthenticationSuccess(request: HttpServletRequest?, response: HttpServletResponse?, authentication: Authentication?) {
response?.sendRedirect(request?.getHeader(HttpHeaders.REFERER))
}
}
class SecurityConfigTH(@Autowired private val myHandler: MyS) : WebSecurityConfigurerAdapter() {
...
.formLogin()
.loginPage("/en/login")
.successHandler(myHandler)
.permitAll()
}
I cannot achieve the same effect. I tried redirect to referrer, but in this case referrer is /en/login page.
Basically:
- User try to access protected url
/protected - Redirect user to
/loginpage - After authentication user should be redirected to
/protectedagain
How to do it with custom successHandler?