Spring Security: проверьте, является ли пользователь файлом cookie cookie.
В этом примере Spring Security показано, как проверить, входит ли пользователь в файл cookie «Запомнить меня».
private boolean isRememberMeAuthenticated() {
Authentication authentication =
SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return false;
}
return RememberMeAuthenticationToken.class.isAssignableFrom(authentication.getClass());
}
@RequestMapping(value = "/admin/update**", method = RequestMethod.GET)
public ModelAndView updatePage() {
ModelAndView model = new ModelAndView();
if (isRememberMeAuthenticated()) {
model.setViewName("/login");
} else {
model.setViewName("update");
}
return model;
}
В теге Spring Security вы можете кодировать так:
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@page session="true"%>
# This user is login by "Remember Me Cookies".
# This user is login by username / password.
Note
isRememberMe () - возвращает true, если текущий участник является запомнившим меня пользователем.
isFullyAuthenticated () - возвращает true, если пользователь не анонимный или запоминающийся пользователь