Вы можете принести хэш часть в форму авторизации и отправить хэш обратно после успешного входа в систему.
Принесите хэш часть с представлением формы Логин:
<form name='login_form' action="/perform_login" method='POST' onsubmit="getHashPart()">
<table>
<tr>
<td>User:</td>
<td><input type='text' name='username' value=''></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password'/></td>
</tr>
<input type="hidden" name="hashPart" value=""/>
<tr>
<td><input name="submit" type="submit" value="submit"/></td>
</tr>
</table>
</form>
<script type="text/javascript">
var getHashPart = function() {
login_form.hashPart.value = location.hash;
}
</script>
Создать MyAuthenticationSuccessHandler:
public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws ServletException, IOException {
String hashPart = request.getParameter("hashPart");
if (hashPart == null || hashPart.trim().equals("")) {
super.onAuthenticationSuccess(request, response, authentication);
} else {
this.getRedirectStrategy().sendRedirect(request, response, "/" + hashPart);
}
}
}
Поместите свой обработчик в SecurityConfig:
http
......
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/perform_login")
.successHandler(myAuthenticationSuccessHandler)