Closed vkuchyn closed 10 years ago
Такая стратегия переадресации из коробки. Есть тест, который проходит: ua.com.itinterview.web.resource.UserResourceIntegrationTest.testReturnToTargetAfterSuccessLogin(). Но если писать реализацию:
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
SavedRequest initReq = new HttpSessionRequestCache().getRequest(request, response);
if (initReq != null){
setDefaultTargetUrl(initReq.getRedirectUrl());
} else {
UserSecurityDetail userSecurityDetail = (UserSecurityDetail) authentication
.getPrincipal();
setDefaultTargetUrl("/user/" + userSecurityDetail.getInfo().getId() + "/view");
}
super.onAuthenticationSuccess(request, response, authentication);
}
Вопроc: для чего сохранять SecurityContext в сессии?
public Authentication loginUser(String userName, String password, HttpServletRequest request) {
Authentication authentication = null;
authentication = tryToAuthenticate(userName, password);
SecurityContextHolder.getContext().setAuthentication(authentication);
HttpSession session = request.getSession();
session.setAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
SecurityContextHolder.getContext());
return authentication;
}
Это неправильно: http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#tech-intro-sec-context-persistence
Фиксить после того, как заведется issue?
После авторизации пользователь должен быть переадресован на запрашиваемую страницу, если такой нету - то на страницу профиля