class UserInfoAPIController {

    @RequestMapping(method = RequestMethod.GET, value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody AcmUserInfoDTO info(Authentication auth, HttpSession session)
    {
        log.debug("Getting info for user {}", auth.getName());

        List<String> authorities = auth.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());

        AcmUser user = (AcmUser) session.getAttribute("acm_user");

        Map<String, Boolean> privilegeMap = (Map<String, Boolean>) session.getAttribute("acm_privileges");
        Set<String> privileges = privilegeMap.keySet();

        String notificationMessage = (String) session.getAttribute("acm_user_message");

        AcmUserInfoDTO retval = new AcmUserInfoDTO();
        retval.setUserId(auth.getName());
        retval.setFullName(user.getFullName());
        retval.setAuthorities(authorities);
        retval.setPrivileges(privileges);
        retval.setFirstName(user.getFirstName());
        retval.setLastName(user.getLastName());
        retval.setMail(user.getMail());
        retval.setDirectoryName(user.getUserDirectoryName());
        retval.setCountry(user.getCountry());
        retval.setCountryAbbreviation(user.getCountryAbbreviation());
        retval.setDepartment(user.getDepartment());
        retval.setCompany(user.getCompany());
        retval.setTitle(user.getTitle());
        retval.setNotificationMessage(notificationMessage);
        retval.setLangCode(user.getLang());
        return retval;
    }

}