@Test public void testIsAuthenticated404() { IPerson person = new PersonImpl(); person.setUserName(USER_NAME); person.setFullName("john doe"); Mockito.when(personManager.getPerson(req)).thenReturn(person); Mockito.when(portalEventFactory.getPortalEventSessionId(req, person)).thenReturn("id"); req.setSession(null); ModelAndView modelAndView = sessionRESTController.isAuthenticated(req, res); Map<String, Object> attributes = (Map<String, Object>) modelAndView.getModel().get("person"); Assert.assertEquals(404, res.getStatus()); Assert.assertNull(modelAndView.getModel().get("person")); }
@RequestMapping(value = "/session.json", method = RequestMethod.GET) public ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response) { final ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(false); if (session == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { final IPerson person = personManager.getPerson(request); final String key = portalEventFactory.getPortalEventSessionId(request, person); final Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("userName", person.getUserName()); attributes.put("displayName", person.isGuest() ? "Guest" : person.getFullName()); attributes.put( "sessionKey", person.isGuest() ? null : key); attributes.put("version", uPortalVersion); if (swapperManager != null) { String originalUsername = swapperManager.getOriginalUsername(session); if (originalUsername != null) { attributes.put("originalUsername", originalUsername); } } long timeoutMS = 1000l * (long) session.getMaxInactiveInterval(); attributes.put("timeoutMS", timeoutMS); try { attributes.put("serverName", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { logger.warn("Wasn't able to get server information", e); attributes.put("serverName", "unknown"); } mv.addObject("person", attributes); } mv.setViewName("json"); return mv; }
SessionRESTController { @RequestMapping(value = "/session.json", method = RequestMethod.GET) public ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response) { final ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(false); if (session == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { final IPerson person = personManager.getPerson(request); final String key = portalEventFactory.getPortalEventSessionId(request, person); final Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("userName", person.getUserName()); attributes.put("displayName", person.isGuest() ? "Guest" : person.getFullName()); attributes.put( "sessionKey", person.isGuest() ? null : key); attributes.put("version", uPortalVersion); if (swapperManager != null) { String originalUsername = swapperManager.getOriginalUsername(session); if (originalUsername != null) { attributes.put("originalUsername", originalUsername); } } long timeoutMS = 1000l * (long) session.getMaxInactiveInterval(); attributes.put("timeoutMS", timeoutMS); try { attributes.put("serverName", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { logger.warn("Wasn't able to get server information", e); attributes.put("serverName", "unknown"); } mv.addObject("person", attributes); } mv.setViewName("json"); return mv; } }
SessionRESTController { @RequestMapping(value = "/session.json", method = RequestMethod.GET) public ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response) { final ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(false); if (session == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { final IPerson person = personManager.getPerson(request); final String key = portalEventFactory.getPortalEventSessionId(request, person); final Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("userName", person.getUserName()); attributes.put("displayName", person.isGuest() ? "Guest" : person.getFullName()); attributes.put( "sessionKey", person.isGuest() ? null : key); attributes.put("version", uPortalVersion); if (swapperManager != null) { String originalUsername = swapperManager.getOriginalUsername(session); if (originalUsername != null) { attributes.put("originalUsername", originalUsername); } } long timeoutMS = 1000l * (long) session.getMaxInactiveInterval(); attributes.put("timeoutMS", timeoutMS); try { attributes.put("serverName", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { logger.warn("Wasn't able to get server information", e); attributes.put("serverName", "unknown"); } mv.addObject("person", attributes); } mv.setViewName("json"); return mv; }  }
SessionRESTController { @RequestMapping(value = "/session.json", method = RequestMethod.GET) public ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response) { final ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(false); if (session == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { final IPerson person = personManager.getPerson(request); final String key = portalEventFactory.getPortalEventSessionId(request, person); final Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("userName", person.getUserName()); attributes.put("displayName", person.isGuest() ? "Guest" : person.getFullName()); attributes.put( "sessionKey", person.isGuest() ? null : key); attributes.put("version", uPortalVersion); if (swapperManager != null) { String originalUsername = swapperManager.getOriginalUsername(session); if (originalUsername != null) { attributes.put("originalUsername", originalUsername); } } long timeoutMS = 1000l * (long) session.getMaxInactiveInterval(); attributes.put("timeoutMS", timeoutMS); try { attributes.put("serverName", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { logger.warn("Wasn't able to get server information", e); attributes.put("serverName", "unknown"); } mv.addObject("person", attributes); } mv.setViewName("json"); return mv; }  @Value("${org.apereo.portal.version}") void setVersion(String version); @Autowired(required = true) void setPersonManager(IPersonManager personManager); @Autowired(required = true) void setSwapperManager(IdentitySwapperManager ism); @Autowired void setPortalEventFactory(IPortalEventFactory pef); @RequestMapping(value = "/session.json", method = RequestMethod.GET) ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response); }
SessionRESTController { @RequestMapping(value = "/session.json", method = RequestMethod.GET) public ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response) { final ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(false); if (session == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { final IPerson person = personManager.getPerson(request); final String key = portalEventFactory.getPortalEventSessionId(request, person); final Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("userName", person.getUserName()); attributes.put("displayName", person.isGuest() ? "Guest" : person.getFullName()); attributes.put( "sessionKey", person.isGuest() ? null : key); attributes.put("version", uPortalVersion); if (swapperManager != null) { String originalUsername = swapperManager.getOriginalUsername(session); if (originalUsername != null) { attributes.put("originalUsername", originalUsername); } } long timeoutMS = 1000l * (long) session.getMaxInactiveInterval(); attributes.put("timeoutMS", timeoutMS); try { attributes.put("serverName", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { logger.warn("Wasn't able to get server information", e); attributes.put("serverName", "unknown"); } mv.addObject("person", attributes); } mv.setViewName("json"); return mv; }  @Value("${org.apereo.portal.version}") void setVersion(String version); @Autowired(required = true) void setPersonManager(IPersonManager personManager); @Autowired(required = true) void setSwapperManager(IdentitySwapperManager ism); @Autowired void setPortalEventFactory(IPortalEventFactory pef); @RequestMapping(value = "/session.json", method = RequestMethod.GET) ModelAndView isAuthenticated(HttpServletRequest request, HttpServletResponse response);  }