class MenuLinksHandlerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        if (modelAndView != null && !(modelAndView.getView() instanceof RedirectView || modelAndView.getViewName().startsWith("redirect:"))) {
            UserResource user = userAuthenticationService.getAuthenticatedUser(request);
            addUserDashboardLink(request, modelAndView);
            addUserProfileLink(request, modelAndView);
            addLogoutLink(modelAndView, logoutUrl);
            addShowManageUsersAttribute(user, modelAndView);
            addShowManageAssessorsAttribute(user, modelAndView);
            Optional.of(handler)
                    .filter(HandlerMethod.class::isInstance)
                    .map(HandlerMethod.class::cast)
                    .ifPresent(handlerMethod -> pageHistoryService.recordPageHistory(request, response, modelAndView, handlerMethod));
        }
    }

}