* org.springframework.web.bind.support.WebDataBinderFactory)
*/
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
User currentUser = getUserContext().getCurrentUser();
String userParam = webRequest.getParameter("ownerId");
if (StringUtils.isNotBlank(userParam) && currentUser.getRole().hasPermission(Permission.SWITCH_TO_ANYONE)) {
return getUserService().getOne(userParam);
}
// User want to do something through other User status and this
// switchUser is other user Id
String switchUser = null;
Cookie[] cookies = getCookies(webRequest);
if (cookies != null) {
for (Cookie cookie : cookies) {
if ("switchUser".equals(cookie.getName()) && cookie.getMaxAge() != 0) {
switchUser = cookie.getValue();
}
}
}
// Let this can be done with parameter as well.
switchUser = StringUtils.defaultIfBlank(webRequest.getParameter("switchUser"), switchUser);
if (currentUser.getUserId().equals(switchUser)) {
currentUser.setOwnerUser(null);
} else if (StringUtils.isNotEmpty(switchUser)) {
User ownerUser = getUserService().getOne(switchUser);
// CurrentUser should remember whose status he used
if (currentUser.getRole().hasPermission(Permission.SWITCH_TO_ANYONE)
|| (ownerUser.getFollowers() != null && ownerUser.getFollowers().contains(currentUser))) {
currentUser.setOwnerUser(ownerUser);
return ownerUser;
}
} else if (StringUtils.isEmpty(switchUser)) {
currentUser.setOwnerUser(null);