List of usage examples for javax.servlet.http HttpSession isNew
public boolean isNew();
true
if the client does not yet know about the session or if the client chooses not to join the session. From source file:cn.powerdash.libsystem.common.security.authc.SessionTimeoutAuthenticationFilter.java
@Override protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response) throws IOException { saveRequest(request);//from ww w . j a v a 2 s . c o m HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (WebUtil.isAjaxRequest(req)) { ObjectMapper objectMapper = new ObjectMapper(); res.setContentType("application/json;charset=UTF-8"); res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); ResultDto<String> error = new ResultDto<String>(); error.setCode(ResultCode.SESSION_TIME_OUT); error.setMessage(MessageUtil.getMessage(SESSION_TIMEOUT_MSG)); objectMapper.writeValue(response.getWriter(), error); LOGGER.debug("session time out for ajax request:{}", req.getRequestURI()); } else { LOGGER.debug("session time out for request:{}", req.getRequestURI()); req.getSession().setAttribute(SESSION_TIMEOUT, true); redirectToLogin(request, response); } HttpSession session = req.getSession(false); if (session != null) { LOGGER.debug( "session time out with id: {}, is sesion new:{}, started: {}, last accessed: {}, request headers: {}", session.getId(), session.isNew(), DateFormatUtils.format(session.getCreationTime(), DATE_FORMAT), DateFormatUtils.format(session.getLastAccessedTime(), DATE_FORMAT), getHeaderString(request)); } else { LOGGER.debug("session time out, no session available for current request"); } }
From source file:org.frat.common.security.authc.SessionTimeoutAuthenticationFilter.java
@Override protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response) throws IOException { saveRequest(request);/* www . j a va2 s. co m*/ HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (WebUtil.isAjaxRequest(req)) { ObjectMapper objectMapper = new ObjectMapper(); res.setContentType("application/json;charset=UTF-8"); res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); ResultDto error = new ResultDto(); error.setCode(ResultCode.SESSION_TIME_OUT); error.setMessage(MessageUtil.getMessage(SESSION_TIMEOUT_MSG)); objectMapper.writeValue(response.getWriter(), error); LOGGER.debug("session time out for ajax request:{}", req.getRequestURI()); } else { LOGGER.debug("session time out for request:{}", req.getRequestURI()); req.getSession().setAttribute(SESSION_TIMEOUT, true); redirectToLogin(request, response); } HttpSession session = req.getSession(false); if (session != null) { LOGGER.debug( "session time out with id:" + " {}, is sesion new:{}, started: {}, last accessed: {}, request headers: {}", session.getId(), session.isNew(), DateFormatUtils.format(session.getCreationTime(), DATE_FORMAT), DateFormatUtils.format(session.getLastAccessedTime(), DATE_FORMAT), getHeaderString(request)); } else { LOGGER.debug("session time out, no session available for current request"); } }
From source file:com.huateng.ebank.framework.session.SessionManager.java
public HttpSession getNewSession(HttpServletRequest req) { if (logger.isDebugEnabled()) { logger.debug("getNewSession(HttpServletRequest) - start"); //$NON-NLS-1$ }//from w w w . j a v a2 s.c om HttpSession session = req.getSession(true); long currentTime = System.currentTimeMillis(); if (true == session.isNew()) session.setAttribute("sessionCreationTime", String.valueOf(currentTime)); logger.debug("Start sessionLastAccessedTime"); session.setAttribute("sessionLastAccessedTime", String.valueOf(currentTime)); logger.debug("sessionLastAccessedTime = " + session.getAttribute("sessionLastAccessedTime")); // String strBetweenSessionTime = // System.getProperty("sessionBetweenSessionTime") ; // long timeOut = Long.valueOf(strBetweenSessionTime).longValue() / 1000 // ; // session.setMaxInactiveInterval((int)timeOut) ; if (logger.isDebugEnabled()) { logger.debug("getNewSession(HttpServletRequest) - end"); //$NON-NLS-1$ } return session; }
From source file:com.huateng.ebank.framework.session.SessionManager.java
public void getSessionAndRefresh(HttpServletRequest req) { if (logger.isDebugEnabled()) { logger.debug("getSessionAndRefresh(HttpServletRequest) - start"); //$NON-NLS-1$ }//from w w w . j av a2s . c o m HttpSession session = req.getSession(false); if (null != session) { long currentTime = System.currentTimeMillis(); if (true == session.isNew()) session.setAttribute("sessionCreationTime", String.valueOf(currentTime)); session.setAttribute("sessionLastAccessedTime", String.valueOf(currentTime)); } if (logger.isDebugEnabled()) { logger.debug("getSessionAndRefresh(HttpServletRequest) - end"); //$NON-NLS-1$ } return; }
From source file:cn.itcast.bbs.controller.BbsServlet.java
private void showAllTopic(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w . j a va 2s. co m int id = Integer.parseInt(request.getParameter("typeId")); //?? List<Topic> topicList = service.showAllTopicByTypeId(id); request.setAttribute("topicList", topicList); request.setAttribute("typeId", id); // HttpSession session = request.getSession(); if (!session.isNew()) { List<Integer> typeIdList = (List<Integer>) session.getAttribute("typeIdList"); if (typeIdList == null) { typeIdList = new ArrayList<Integer>(); session.setAttribute("typeIdList", typeIdList); } boolean flag = service.isClicked(id, typeIdList); if (!flag) { service.updateTypeClick(id); } } request.getRequestDispatcher("/WEB-INF/bbs/listAllTopic.jsp").forward(request, response); } catch (Exception e) { e.printStackTrace(); request.setAttribute("message", "?"); request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response); } }
From source file:gov.nih.nci.security.upt.actions.ProtectionGroupAction.java
public String loadParentAssociation() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logProtectionGroup.isDebugEnabled()) logProtectionGroup.debug("||" + protectionGroupForm.getFormName() + "|loadParentAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }//from ww w . j a v a 2 s. c o m Collection associatedProtectionGroup = (Collection) new HashSet(); protectionGroupForm.buildDisplayForm(userProvisioningManager); if (protectionGroupForm.getProtectionGroupParentProtectionGroup() != null) associatedProtectionGroup.add(protectionGroupForm.getProtectionGroupParentProtectionGroup()); ProtectionGroup protectionGroup = new ProtectionGroup(); SearchCriteria searchCriteria = new ProtectionGroupSearchCriteria(protectionGroup); Collection totalProtectionGroups = (Collection) userProvisioningManager.getObjects(searchCriteria); Collection availableProtectionGroups = ObjectSetUtil.minus(totalProtectionGroups, associatedProtectionGroup); Collection protectionGroupList = (Collection) new HashSet(); protectionGroupList.add(userProvisioningManager.getProtectionGroupById(protectionGroupForm.getPrimaryId())); availableProtectionGroups = ObjectSetUtil.minus(availableProtectionGroups, protectionGroupList); request.setAttribute(DisplayConstants.ASSIGNED_SET, associatedProtectionGroup); request.setAttribute(DisplayConstants.AVAILABLE_SET, availableProtectionGroups); if (logProtectionGroup.isDebugEnabled()) logProtectionGroup.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + protectionGroupForm.getFormName() + "|loadParentAssociation|Success|Success in Loading Parent Association for " + protectionGroupForm.getFormName() + " object|" + "|"); return ForwardConstants.LOAD_PARENT_ASSOCIATION_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.ProtectionGroupAction.java
public String setParentAssociation() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logProtectionGroup.isDebugEnabled()) logProtectionGroup.debug("||" + protectionGroupForm.getFormName() + "|setParentAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }/*from www .j ava2 s .c o m*/ UserInfoHelper.setUserInfo(((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId(), session.getId()); try { // TO-DO replace assignProtectionGroups with setOwners or such method String parentProtectionGroupId = null; if (protectionGroupForm.getParentAssociatedIds() != null && (protectionGroupForm.getParentAssociatedIds().length == 1)) { parentProtectionGroupId = protectionGroupForm.getParentAssociatedIds()[0]; } else { parentProtectionGroupId = null; } userProvisioningManager.assignParentProtectionGroup(parentProtectionGroupId, protectionGroupForm.getProtectionGroupId()); protectionGroupForm.setRequest(request); protectionGroupForm.buildDisplayForm(userProvisioningManager); addActionMessage("Association Update Successful"); } catch (CSException cse) { addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage())); if (logProtectionGroup.isDebugEnabled()) logProtectionGroup.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + protectionGroupForm.getFormName() + "|setParentAssociation|Failure|Error Loading Protection Group Association for the " + protectionGroupForm.getFormName() + " object|" + "|" + cse.getMessage()); } if (logProtectionGroup.isDebugEnabled()) logProtectionGroup.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + protectionGroupForm.getFormName() + "|setParentAssociation|Success|Success in Setting Parent Association for " + protectionGroupForm.getFormName() + " object|" + "|"); return ForwardConstants.SET_PARENT_ASSOCIATION_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String loadDoubleAssociation(BaseDoubleAssociationForm baseDoubleAssociationForm) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug("||" + baseDoubleAssociationForm.getFormName() + "|loadDoubleAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }/*from w ww . j av a 2 s. c o m*/ session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0"); try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); baseDoubleAssociationForm.buildDoubleAssociationObject(userProvisioningManager); } catch (CSException cse) { addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage())); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadDoubleAssociation|Failure|Error Loading Double Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadDoubleAssociation|Success|Success in Loading Double Association for " + baseDoubleAssociationForm.getFormName() + " object|" + "|"); return ForwardConstants.LOAD_DOUBLEASSOCIATION_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String unlock(UserForm userForm) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug("||" + userForm.getFormName() + "|unlock|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }// w w w . j av a 2s .c o m String userLoginName = userForm.getUserLoginName(); String loginId = ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId(); UserInfoHelper.setUserInfo(loginId, session.getId()); try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); userForm.setRequest(request); LockoutManager.getInstance().unLockUser(userLoginName); userForm.buildDBObject(userProvisioningManager); addActionMessage("UnLock Successful"); } catch (CSException cse) { addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage())); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + userLoginName + "|" + userForm.getFormName() + "|unlock|Failure|Error unlock the " + userForm.getFormName() + " object|" + "|" + cse.getMessage()); } session.setAttribute(DisplayConstants.CURRENT_FORM, userForm); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + userLoginName + "|" + userForm.getFormName() + "|unlock|Success|Updating existing " + userForm.getFormName() + " object|" + "|"); return ForwardConstants.UNLOCK_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String setDoubleAssociation(BaseDoubleAssociationForm baseDoubleAssociationForm) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug("||" + baseDoubleAssociationForm.getFormName() + "|setDoubleAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }//from ww w. jav a 2 s. co m UserInfoHelper.setUserInfo(((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId(), session.getId()); try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); baseDoubleAssociationForm.buildDisplayForm(userProvisioningManager); baseDoubleAssociationForm.setDoubleAssociationObject(userProvisioningManager); addActionMessage("Association Update Successful"); } catch (CSException cse) { addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage())); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|setDoubleAssociation|Failure|Error Setting Double Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|setDoubleAssociation|Success|Success in Setting Double Association for " + baseDoubleAssociationForm.getFormName() + " object|" + "|"); return ForwardConstants.SET_DOUBLEASSOCIATION_SUCCESS; }