List of usage examples for javax.servlet.http HttpSession getMaxInactiveInterval
public int getMaxInactiveInterval();
From source file:com.jredrain.session.HttpSessionFilter.java
private Map loadSessionData(String sessionId, HttpSession rawSession) { Map sessionData = null;//from w ww .ja v a 2 s.c o m try { sessionData = sessionStore.getSession(sessionId, rawSession.getMaxInactiveInterval()); } catch (Exception e) { sessionData = new HashMap(); logger.warn("load session data error,cause:" + e, e); } return sessionData; }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // Get the current session object, create one if necessary HttpSession session = req.getSession(); out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>"); out.println("<BODY><H1>Session Timer</H1>"); // Display the previous timeout out.println("The previous timeout was " + session.getMaxInactiveInterval()); out.println("<BR>"); // Set the new timeout session.setMaxInactiveInterval(2 * 60 * 60); // two hours // Display the new timeout out.println("The newly assigned timeout is " + session.getMaxInactiveInterval()); out.println("</BODY></HTML>"); }
From source file:com.cruz.sec.config.SessionExpirationFilter.java
@Override public void onApplicationEvent(HttpSessionDestroyedEvent event) { List<org.springframework.security.core.context.SecurityContext> lstSecurityContext = event .getSecurityContexts();/*from w w w .j av a 2s.c om*/ UserDetails ud; for (org.springframework.security.core.context.SecurityContext securityContext : lstSecurityContext) { ud = (UserDetails) securityContext.getAuthentication().getPrincipal(); System.out.println("OBJECTO SESION DESTRUIDO: " + ud.toString()); HttpSession httpSession = event.getSession(); // long createdTime = httpSession.getCreationTime(); long lastAccessedTime = httpSession.getLastAccessedTime(); int maxInactiveTime = httpSession.getMaxInactiveInterval(); long currentTime = System.currentTimeMillis(); // System.out.println("Session Id :"+httpSession.getId() ); // System.out.println("Created Time : " + createdTime); // System.out.println("Last Accessed Time : " + lastAccessedTime); // System.out.println("Current Time : " + currentTime); boolean possibleSessionTimeout = (currentTime - lastAccessedTime) >= (maxInactiveTime * 1000); if (possibleSessionTimeout) { System.out.println("SESIN CERRADA POR INACTIVIDAD"); //Se realiza la peticin al Node JS // requestNodeJS.sendRequestWithUsernameAndMethod(ud.getUsername(), "/session-close"); } } }
From source file:com.gs.config.SessionExpirationFilter.java
@Override public void onApplicationEvent(HttpSessionDestroyedEvent event) { List<org.springframework.security.core.context.SecurityContext> lstSecurityContext = event .getSecurityContexts();/*w ww . j a va 2 s. c o m*/ UserDetails ud; for (org.springframework.security.core.context.SecurityContext securityContext : lstSecurityContext) { ud = (UserDetails) securityContext.getAuthentication().getPrincipal(); System.out.println("SESIN DESTRUIDA: " + ud.toString()); HttpSession httpSession = event.getSession(); // long createdTime = httpSession.getCreationTime(); long lastAccessedTime = httpSession.getLastAccessedTime(); int maxInactiveTime = httpSession.getMaxInactiveInterval(); long currentTime = System.currentTimeMillis(); // System.out.println("Session Id :"+httpSession.getId() ); // System.out.println("Created Time : " + createdTime); // System.out.println("Last Accessed Time : " + lastAccessedTime); // System.out.println("Current Time : " + currentTime); boolean possibleSessionTimeout = (currentTime - lastAccessedTime) >= (maxInactiveTime * 1000); if (possibleSessionTimeout) { //Se realiza la peticin al Node JS // requestNodeJS.sendRequestWithUsernameAndMethod(ud.getUsername(), "/session-close"); } // System.out.println("Possbile Timeout : " + possibleSessionTimeout); } }
From source file:org.mifos.application.admin.business.service.ViewOrganizationSettingsServiceFacadeWebTier.java
private Properties getMiscRules(HttpSession httpSession) { Properties misc = new Properties(); Integer timeoutVal = httpSession.getMaxInactiveInterval() / 60; misc.setProperty("sessionTimeout", timeoutVal.toString()); // FIXME - #00001 - keithw - Check days in advance usage in CollectionsheetHelper // Integer advanceDaysVal = CollectionSheetHelper.getDaysInAdvance(); misc.setProperty("collectionSheetAdvanceDays", "1"); misc.setProperty("backDatedTransactions", booleanToYesNo(AccountingRules.isBackDatedTxnAllowed())); ConfigurationBusinessService cbs = new ConfigurationBusinessService(); misc.setProperty("glim", booleanToYesNo(cbs.isGlimEnabled())); misc.setProperty("lsim", booleanToYesNo(cbs.isRepaymentIndepOfMeetingEnabled())); return misc;//from www.j a v a 2 s . co m }
From source file:org.mifos.application.admin.struts.action.ViewOrganizationSettingsAction.java
private Properties getMiscRules(HttpSession httpSession) throws ServiceException { Properties misc = new Properties(); Integer timeoutVal = httpSession.getMaxInactiveInterval() / 60; misc.setProperty("sessionTimeout", timeoutVal.toString()); try {//from ww w .j ava2 s . c om Integer advanceDaysVal = CollectionSheetHelper.getDaysInAdvance(); misc.setProperty("collectionSheetAdvanceDays", advanceDaysVal.toString()); } catch (PersistenceException e) { throw new RuntimeException(e); } misc.setProperty("backDatedTransactions", booleanToYesNo(AccountingRules.isBackDatedTxnAllowed())); ConfigurationBusinessService cbs = new ConfigurationBusinessService(); misc.setProperty("glim", booleanToYesNo(cbs.isGlimEnabled())); misc.setProperty("lsim", booleanToYesNo(cbs.isRepaymentIndepOfMeetingEnabled())); return misc; }
From source file:com.boundlessgeo.geoserver.api.controllers.SessionsController.java
@RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd'T'HH:mm:ssZ"); JSONArr arr = new JSONArr(); for (HttpSession session : AppSessionDebugger.list()) { JSONObj obj = arr.addObject();//from w w w .j a v a 2 s .co m obj.put("id", session.getId()).put("created", dateFormat.format(new Date(session.getCreationTime()))) .put("updated", dateFormat.format(new Date(session.getLastAccessedTime()))) .put("timeout", session.getMaxInactiveInterval()); @SuppressWarnings("unchecked") Enumeration<String> attNames = session.getAttributeNames(); JSONObj atts = obj.putObject("attributes"); while (attNames.hasMoreElements()) { String attName = attNames.nextElement(); atts.put(attName, session.getAttribute(attName).toString()); } } return arr; }
From source file:org.sakaiproject.tool.assessment.ui.web.session.SessionUtil.java
/** * Sets the current <code>HttpSession</code> maxInactiveInterval value * @param context the faces context/* www . j a v a 2 s . c o m*/ * @param delivery the delivery bean * @param beginAssessment true if called from the beginning of an assessment, otherwise false * * @see org.sakaiproject.tool.assessment.ui.bean.delivery.DeliveryBean */ public static void setSessionTimeout(FacesContext context, DeliveryBean delivery, boolean beginAssessment) { if (!IntegrationContextFactory.getInstance().isIntegrated()) { return; } ExternalContext exContext = context.getExternalContext(); HttpSession session = (HttpSession) exContext.getSession(false); if (session == null) { return; } /** if we have a tool session then get big session (MySession) */ if (session instanceof ToolSession) { session = (HttpSession) SessionManager.getCurrentSession(); } synchronized (session) { if (beginAssessment) { /** * if we have not already set value * (ensure setSessionTimeout is called only once at beginning of assessment) */ int interval = DEFAULT_APP_INTERVAL_VAL; if (session.getAttribute(EXTERNAL_APP_INTERVAL) == null) { if (delivery != null && delivery.getHasTimeLimit()) { interval = delivery.getTimeLimit_hour() * HOURS_TO_SECONDS_MULTIPLIER; interval += delivery.getTimeLimit_minute() * MINUTES_TO_SECONDS_MULTIPLIER; } else { /** for assessments without time limit */ interval = DEFAULT_APP_INTERVAL_VAL; } } if (interval > session.getMaxInactiveInterval()) { if (log.isDebugEnabled()) { log.debug("begin_assessment: Setting session " + session.getId() + " inactive interval= " + interval + " seconds"); } /** store current interval value */ session.setAttribute(EXTERNAL_APP_INTERVAL, Integer.valueOf(session.getMaxInactiveInterval())); session.setMaxInactiveInterval(interval + INTERVAL_BUFFER); } } else { /** on assessment submission or 'save and exit' from assessment */ Integer returnVal = (Integer) session.getAttribute(EXTERNAL_APP_INTERVAL); if (returnVal == null) { return; } else { session.removeAttribute(EXTERNAL_APP_INTERVAL); if (log.isDebugEnabled()) { log.debug("end_assessment: Setting session " + session.getId() + " inactive interval= " + returnVal + " seconds"); } /** set to value of interval before taking */ session.setMaxInactiveInterval(returnVal.intValue()); } } } }
From source file:MyServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); out.println("<html>"); out.println("<head>"); out.println("<title>Simple Session Tracker</title>"); out.println("</head>"); out.println("<body>"); out.println("<h2>Session Info</h2>"); out.println("session Id: " + session.getId() + "<br><br>"); out.println("The SESSION TIMEOUT period is " + session.getMaxInactiveInterval() + " seconds.<br><br>"); out.println("Now changing it to 20 minutes.<br><br>"); session.setMaxInactiveInterval(20 * 60); out.println("The SESSION TIMEOUT period is now " + session.getMaxInactiveInterval() + " seconds."); out.println("</body>"); out.println("</html>"); }
From source file:org.owasp.webgoat.service.SessionService.java
/** * Returns hints for current lesson/* www . j a v a2 s. c o m*/ * * @param session a {@link javax.servlet.http.HttpSession} object. * @param request a {@link javax.servlet.http.HttpServletRequest} object. * @return a {@link java.lang.String} object. */ @RequestMapping(value = "/session.mvc", produces = "application/json") public @ResponseBody String showSession(HttpServletRequest request, HttpSession session) { StringBuilder sb = new StringBuilder(); sb.append("id").append(" = ").append(session.getId()).append("\n"); sb.append("created").append(" = ").append(new Date(session.getCreationTime())).append("\n"); sb.append("last access").append(" = ").append(new Date(session.getLastAccessedTime())).append("\n"); sb.append("timeout (secs)").append(" = ").append(session.getMaxInactiveInterval()).append("\n"); sb.append("session from cookie?").append(" = ").append(request.isRequestedSessionIdFromCookie()) .append("\n"); sb.append("session from url?").append(" = ").append(request.isRequestedSessionIdFromURL()).append("\n"); sb.append("=====================================\n"); // get attributes List<String> attributes = new ArrayList<String>(); Enumeration keys = session.getAttributeNames(); while (keys.hasMoreElements()) { String name = (String) keys.nextElement(); attributes.add(name); } Collections.sort(attributes); for (String attribute : attributes) { String value = session.getAttribute(attribute) + ""; sb.append(attribute).append(" = ").append(value).append("\n"); } return sb.toString(); }