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:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String setRoleAssociation(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() + "|setRoleAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }// w w w . j a v a2 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.updateRoleAssociation(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() + "|setRoleAssociation|Failure|Error Setting Role Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + logDoubleAssociation.toString() + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|setRoleAssociation|Success|Success in Setting Role Association for " + baseDoubleAssociationForm.getFormName() + " object|" + logDoubleAssociation.toString() + "|"); return ForwardConstants.SET_ROLEASSOCIATION_SUCCESS; }
From source file:org.apache.geode.modules.session.TestSessionsBase.java
/** * Test that calling session.isNew() works for the initial as well as subsequent requests. */// www. j a v a 2s . c om @Test public void testIsNew() throws Exception { Callback c = new Callback() { @Override public void call(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); response.getWriter().write(Boolean.toString(session.isNew())); } }; servlet.getServletContext().setAttribute("callback", c); WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port)); req.setParameter("cmd", QueryCommand.CALLBACK.name()); req.setParameter("param", "callback"); WebResponse response = wc.getResponse(req); assertEquals("true", response.getText()); response = wc.getResponse(req); assertEquals("false", response.getText()); }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String loadRoleAssociation(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() + "|loadRoleAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }/* ww w. j ava2s . co m*/ session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0"); if (baseDoubleAssociationForm.getProtectionGroupAssociatedId() == null || baseDoubleAssociationForm.getProtectionGroupAssociatedId().equalsIgnoreCase("")) { addActionError("A record needs to be selected first"); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadRoleAssociation|Failure|No Protection Group Id selected for " + baseDoubleAssociationForm.getFormName() + " object||"); return ForwardConstants.LOAD_PROTECTIONGROUPASSOCIATION_SUCCESS; } try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); baseDoubleAssociationForm.buildRoleAssociationObject(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() + "|loadRoleAssociation|Failure|Error Loading Role Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadRoleAssociation|Success|Success in Loading Role Association for " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|"); return ForwardConstants.LOAD_ROLEASSOCIATION_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String removeProtectionGroupAssociation(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() + "|removeProtectionGroupAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }/*from ww w. j a v a2s . c om*/ UserInfoHelper.setUserInfo(((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId(), session.getId()); if (baseDoubleAssociationForm.getProtectionGroupAssociatedId() == null || baseDoubleAssociationForm.getProtectionGroupAssociatedId().equalsIgnoreCase("")) { addActionError("A record needs to be selected first"); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|removeProtectionGroupAssociation|Failure|No Protection Group Id selected for " + baseDoubleAssociationForm.getFormName() + " object||"); return ForwardConstants.LOAD_PROTECTIONGROUPASSOCIATION_SUCCESS; } try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); baseDoubleAssociationForm.buildDisplayForm(userProvisioningManager); baseDoubleAssociationForm.removeProtectionGroupAssociation(userProvisioningManager); addActionMessage("Protection Group Successfully removed"); } 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() + "|removeProtectionGroupAssociation|Failure|Error Removing Protection Group Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|removeGroupAssociation|Success|Success in Removing Protection Group Association for " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|"); return ForwardConstants.REMOVE_PROTECTIONGROUPASSOCIATION_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String loadProtectionGroupAssociation(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() + "|loadProtectionGroupAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }// w w w .ja v a 2 s . c om session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0"); try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); Collection temp = baseDoubleAssociationForm .buildProtectionGroupAssociationObject(userProvisioningManager); List associatedProtectionGroupRoleContexts = new ArrayList(); Iterator iterator = temp.iterator(); while (iterator.hasNext()) { associatedProtectionGroupRoleContexts.add(iterator.next()); } Collections.sort(associatedProtectionGroupRoleContexts, new ProtectionGroupRoleContextComparator()); if (associatedProtectionGroupRoleContexts.size() != 0) session.setAttribute(DisplayConstants.AVAILABLE_PROTECTIONGROUPROLECONTEXT_SET, associatedProtectionGroupRoleContexts); else { addActionError("No Associated Protection Group or Roles found"); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadProtectionGroupAssociation|Failure|No Protection Group Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + logDoubleAssociation.toString() + "|"); return ForwardConstants.LOAD_PROTECTIONGROUPASSOCIATION_FAILURE; } } 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() + "|loadProtectionGroupAssociation|Failure|Error Loading Protection Group Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + logDoubleAssociation.toString() + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadProtectionGroupAssociation|Success|Success in Loading Protection Group Association for " + baseDoubleAssociationForm.getFormName() + " object|" + logDoubleAssociation.toString() + "|"); return ForwardConstants.LOAD_PROTECTIONGROUPASSOCIATION_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String loadProtectionElementPrivilegesAssociation(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() + "|loadProtectionElementPrivilegesAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }//from w w w . ja v a2 s. c om session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0"); try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); Collection temp = baseDoubleAssociationForm .buildProtectionElementPrivilegesObject(userProvisioningManager); List associatedProtectionElementPrivilegesContexts = new ArrayList(); Iterator iterator = temp.iterator(); while (iterator.hasNext()) { associatedProtectionElementPrivilegesContexts.add(iterator.next()); } Collections.sort(associatedProtectionElementPrivilegesContexts, new ProtectionElementPrivilegesContextComparator()); if (associatedProtectionElementPrivilegesContexts != null && associatedProtectionElementPrivilegesContexts.size() != 0) session.setAttribute(DisplayConstants.AVAILABLE_PROTECTIONELEMENTPRIVILEGESCONTEXT_SET, associatedProtectionElementPrivilegesContexts); else { addActionError("No Associated Protection Element or Privileges found"); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadProtectionElementPrivilegesAssociation|Failure|No Protection Element Privileges Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|"); return ForwardConstants.LOAD_PROTECTIONELEMENTPRIVILEGESASSOCIATION_FAILURE; } } 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() + "|loadProtectionElementPrivilegesAssociation|Failure|Error Loading Protection Element Privileges Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadProtectionElementPrivilegesAssociation|Success|Success in Loading Protection Element Privileges Association for " + baseDoubleAssociationForm.getFormName() + " object|" + baseDoubleAssociationForm.toString() + "|"); return ForwardConstants.LOAD_PROTECTIONELEMENTPRIVILEGESASSOCIATION_SUCCESS; }
From source file:org.b3log.solo.SoloServletListener.java
@Override public void requestInitialized(final ServletRequestEvent servletRequestEvent) { final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest(); final String requestURI = httpServletRequest.getRequestURI(); Stopwatchs.start("Request Initialized[requestURI=" + requestURI + "]"); if (Requests.searchEngineBotRequest(httpServletRequest)) { LOGGER.log(Level.FINER, "Request made from a search engine[User-Agent={0}]", httpServletRequest.getHeader("User-Agent")); httpServletRequest.setAttribute(Keys.HttpRequest.IS_SEARCH_ENGINE_BOT, true); } else {/* w w w . j a v a 2 s . c o m*/ // Gets the session of this request final HttpSession session = httpServletRequest.getSession(); LOGGER.log(Level.FINE, "Gets a session[id={0}, remoteAddr={1}, User-Agent={2}, isNew={3}]", new Object[] { session.getId(), httpServletRequest.getRemoteAddr(), httpServletRequest.getHeader("User-Agent"), session.isNew() }); // Online visitor count Statistics.onlineVisitorCount(httpServletRequest); } resolveSkinDir(httpServletRequest); }
From source file:com.oic.net.Callback.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String code = request.getParameter("code"); if (request.getParameter("code") == null) { //OAuth??code???? response.sendRedirect("/"); } else if (request.getParameter("register") != null) { //ID? session.setAttribute("alreadyId", true); return;// w w w . ja v a 2s . c o m } if (session.isNew()) { session.setMaxInactiveInterval(300); } String email = ""; try { getToken(code); System.out.println(code); email = getEmailAddress(); } catch (Exception e) { e.printStackTrace(); } Pattern pattern = Pattern.compile("@oic.jp$"); Matcher matcher = pattern.matcher(email); if (matcher.find()) { Pattern numberPattern = Pattern.compile("^[a-zA-Z][0-9]{4}"); Matcher numberMatcher = numberPattern.matcher(email.toLowerCase()); if (!numberMatcher.find()) { response.getWriter().println("????????"); session.invalidate(); return; } String studentNumber = numberMatcher.group(); String key = DigestUtils.md5Hex(String.valueOf(new Date().getTime())); session.setAttribute("studentNumber", studentNumber); session.setAttribute("key", key); //md5?? registerData(studentNumber, key, session); response.sendRedirect("/"); } else { response.getWriter().println("????????"); session.invalidate(); } }
From source file:gov.nih.nci.security.upt.actions.CommonDBAction.java
public String loadSearch(BaseDBForm baseDBForm) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logDB.isDebugEnabled()) logDB.debug("||" + baseDBForm.getFormName() + "|loadSearch|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }// w ww .j ava 2s .c om baseDBForm.resetForm(); session.setAttribute(DisplayConstants.CURRENT_ACTION, DisplayConstants.SEARCH); session.setAttribute(DisplayConstants.CURRENT_FORM, baseDBForm); if (logDB.isDebugEnabled()) logDB.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDBForm.getFormName() + "|loadSearch|Success|Loading the Search Page||"); return ForwardConstants.LOAD_SEARCH_SUCCESS; }
From source file:gov.nih.nci.security.upt.actions.CommonDBAction.java
public String loadHome(BaseDBForm form) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logDB.isDebugEnabled()) logDB.debug("||" + form.getFormName() + "|loadHome|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }/*from www . j a v a 2s.c o m*/ session.removeAttribute(DisplayConstants.CURRENT_ACTION); session.removeAttribute(DisplayConstants.CURRENT_FORM); session.removeAttribute(DisplayConstants.SEARCH_RESULT); session.removeAttribute(DisplayConstants.CREATE_WORKFLOW); if (logDB.isDebugEnabled()) logDB.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + form.getFormName() + "|loadHome|Success|Load the Home Page||"); return ForwardConstants.LOAD_HOME_SUCCESS; }