List of usage examples for javax.servlet.http HttpSession getAttributeNames
public Enumeration<String> getAttributeNames();
Enumeration
of String
objects containing the names of all the objects bound to this session. From source file:org.owasp.esapi.reference.DefaultHTTPUtilities.java
/** * {@inheritDoc}// www.jav a2 s . c o m */ public HttpSession changeSessionIdentifier(HttpServletRequest request) throws AuthenticationException { // get the current session HttpSession oldSession = request.getSession(); // make a copy of the session content Map<String, Object> temp = new ConcurrentHashMap<String, Object>(); Enumeration e = oldSession.getAttributeNames(); while (e != null && e.hasMoreElements()) { String name = (String) e.nextElement(); Object value = oldSession.getAttribute(name); temp.put(name, value); } // kill the old session and create a new one oldSession.invalidate(); HttpSession newSession = request.getSession(); User user = ESAPI.authenticator().getCurrentUser(); user.addSession(newSession); user.removeSession(oldSession); // copy back the session content for (Map.Entry<String, Object> stringObjectEntry : temp.entrySet()) { newSession.setAttribute(stringObjectEntry.getKey(), stringObjectEntry.getValue()); } return newSession; }
From source file:controllers.controller.java
private void clearNCloseSession(HttpSession session, HttpServletRequest request, HttpServletResponse response, QUID quid, PrintWriter out) throws Exception { String param = ""; Enumeration enu = session.getAttributeNames(); while (enu.hasMoreElements()) { param = enu.nextElement().toString(); session.setAttribute(param, null); session.removeAttribute(param);// w w w . jav a2s.c o m } session.invalidate(); session = null; }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/search", method = RequestMethod.GET) public final ModelAndView siteSearch() { final String methodName = CommonController.CNAME + "#siteSearch()"; if (DEBUG) {//from www .ja v a 2s . c om DEBUGGER.debug(methodName); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Session ID: {}", hSession.getId()); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } mView.addObject("command", new SearchRequest()); mView.setViewName(this.appConfig.getSearchRequestPage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/contact", method = RequestMethod.GET) public final ModelAndView showMessagingPage() { final String methodName = CommonController.CNAME + "#showMessagingPage()"; if (DEBUG) {/*from w ww . j a va 2 s . co m*/ DEBUGGER.debug(methodName); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Session ID: {}", hSession.getId()); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } mView.addObject("svcAddress", this.appConfig.getServiceEmail()); mView.addObject("command", new EmailMessage()); mView.setViewName(this.appConfig.getContactPage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:org.protorabbit.servlet.ProtoRabbitServlet.java
@SuppressWarnings("unchecked") @Override//ww w . ja v a 2 s . co m protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { WebContext wc = null; int bytesServed = 0; long iStartTime = System.currentTimeMillis(); String path = req.getServletPath(); String pathInfo = req.getPathInfo(); String clientId = req.getRemoteAddr(); try { String command = req.getParameter("command"); if (command != null) { if ("ping".equals(command)) { resp.setHeader("pragma", "NO-CACHE"); resp.setHeader("Cache-Control", "no-cache"); resp.getWriter().write((new Date()).getTime() + ""); return; } else if ("timeshift".equals(command)) { long clientTime = Long.parseLong(req.getParameter("clientTime")); resp.setHeader("pragma", "NO-CACHE"); resp.setHeader("Cache-Control", "no-cache"); long timeShift = ((new Date()).getTime() - clientTime); resp.getWriter().write("timeshift=" + timeShift + ";"); return; } else if ("episodesync".equals(command)) { long startTime = Long.parseLong(req.getParameter("timestamp")); long transitTime = Long.parseLong(req.getParameter("transitTime")); Episode e = jcfg.getEpisodeManager().getEpisode(clientId, startTime); if (e == null) { return; } e.setTransitTime(transitTime); Mark m = e.getMark("transit_to"); long transitStartTime = m.getStartTime(); long now = (new Date()).getTime(); long duration = (now - (transitStartTime + transitTime)); // add the page load directly following the start time (add 1 to always make sure it is after transit time) e.addMark(new Mark("page_load", transitStartTime + transitTime + 1)); Measure m1 = new Measure("transit_to", transitTime); // include transit time for this request and intial page load Measure m2 = new Measure("page_load", (duration + transitTime)); e.addMeasure("transit_to", m1); e.addMeasure("page_load", m2); // now - duration is assumed transit time to offset call to this command resp.getWriter().write("var t_firstbyte=new Number(new Date());" + "window.postMessage(\"EPISODES:mark:firstbyte:\" + t_firstbyte, \"*\");"); return; } else if ("stats".equals(command)) { Map<String, Object> stats = new HashMap<String, Object>(); stats.put("cachedResources", jcfg.getCombinedResourceManager().getResources()); stats.put("templates", jcfg.getTemplates()); stats.put("includeFiles", jcfg.getIncludeFiles()); if (json == null) { SerializationFactory factory = new SerializationFactory(); json = factory.getInstance(); } resp.setHeader("pragma", "NO-CACHE"); resp.setHeader("Cache-Control", "no-cache"); Object jo = json.serialize(stats); resp.getWriter().write(jo.toString()); return; } else if ("recordProfile".equals(command)) { long startTime = Long.parseLong(req.getParameter("timestamp")); long timeshift = Long.parseLong(req.getParameter("timeshift")); long timestamp = (new Date()).getTime(); long duration = timestamp - startTime; Episode e = jcfg.getEpisodeManager().getEpisode(clientId, startTime); if (e == null) { getLogger().severe("Unable to find episode " + startTime + " to recourd data into with client " + clientId); return; } e.setTimeshift(timeshift); // make sure to account for transit time Measure m = new Measure("full_request", duration - e.getTransitTime()); e.addMeasure("full_request", m); String data = req.getParameter("data"); JSONObject jo = null; try { jo = new JSONObject(data); jcfg.getEpisodeManager().updateEpisode(clientId, startTime, jo); } catch (JSONException ex) { ex.printStackTrace(); } resp.getWriter().write("ok"); return; } else if ("episodes".equals(command)) { if (json == null) { SerializationFactory factory = new SerializationFactory(); json = factory.getInstance(); } Object data = null; data = jcfg.getEpisodeManager().getEpisodes(); resp.setHeader("pragma", "NO-CACHE"); resp.setHeader("Cache-Control", "no-cache"); Object jo = json.serialize(data); resp.getWriter().write(jo.toString()); return; } else if ("version".equals(command)) { resp.getWriter().write(version); return; } else if ("resetProfiles".equals(command)) { jcfg.getEpisodeManager().reset(); resp.getWriter().write("profiles reset"); return; } else if ("startProfiling".equals(command)) { jcfg.setProfile(true); resp.getWriter().write("profiling enabled"); return; } else if ("stopProfiling".equals(command)) { jcfg.setProfile(false); resp.getWriter().write("profiling disabled"); return; } } else if (pathInfo != null) { for (String t : writeHeaders) { if (pathInfo.endsWith(t)) { writeHeaders(req, resp, pathInfo); return; } } } // check for updates to the templates.json file if (isDevMode) { updateConfig(); } boolean canGzip = false; // check if client supports gzip Enumeration<String> hnum = req.getHeaders("Accept-Encoding"); while (hnum.hasMoreElements()) { String acceptType = hnum.nextElement(); if (acceptType != null && acceptType.indexOf("gzip") != -1) { canGzip = true; break; } } wc = new WebContext(jcfg, ctx, req, resp); wc.setAttribute(Config.START_TIME, new Long(new Date().getTime())); String id = req.getParameter("resourceid"); if (id != null) { processResourceRequest(id, wc, req, resp, canGzip); return; } if (("/" + serviceURI).equals(path)) { path = req.getPathInfo(); } int lastSep = -1; if (path != null) { lastSep = path.lastIndexOf("/"); } String namespace = null; if (lastSep != -1 && lastSep < path.length() - 1) { int nextDot = path.indexOf(".", lastSep + 1); int lastSlash = path.lastIndexOf("/"); if (nextDot != -1) { id = path.substring(lastSep + 1, nextDot); } else { if (lastSlash != -1 && lastSlash < path.length()) { id = path.substring(lastSlash + 1); } } if (lastSlash != -1 && lastSlash < path.length()) { namespace = path.substring(0, lastSlash); } } ITemplate t = null; if (id != null) { t = jcfg.getTemplate(id, wc); if (jcfg.profile()) { long timestamp = (new Date()).getTime(); Episode e = new Episode(timestamp); e.setUserAgent(req.getHeader("user-agent")); e.setClientId(clientId); e.setUri(id); e.addMark(new Mark("full_request", timestamp)); e.addMark(new Mark("server_render", timestamp)); wc.setAttribute(Config.EPISODE, e); wc.setAttribute(Config.DEFAULT_EPISODE_PROCESS, new Boolean(true)); jcfg.getEpisodeManager().addEpisode(e); } } // make sure that if a namespace is required that is is used to access the template. Also account for "" which can // result from the namespace. boolean namespaceOk = true; if (t != null && t.getURINamespace(wc) != null) { if (namespace == null || (namespace != null && "".equals(namespace)) || !t.getURINamespace(wc).startsWith(namespace)) { namespaceOk = false; getLogger().warning( "request for template " + id + " without matching namespace " + t.getURINamespace(wc)); } } if (id == null || t == null || !namespaceOk) { getLogger().warning("template " + id + " requested but not found."); resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // set the template engine IEngine renderEngine = null; if (t.getTemplateURI(wc).getFullURI().endsWith(".st")) { renderEngine = new StringTemplateEngine(); // build up a list of the session/reqeust attributes for string tempalte Map<String, Object> sessionMap = new HashMap<String, Object>(); HttpSession hs = req.getSession(); Enumeration en = hs.getAttributeNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); sessionMap.put(key, hs.getAttribute(key)); } Map<String, Object> requestMap = new HashMap<String, Object>(); Enumeration ren = req.getAttributeNames(); while (ren.hasMoreElements()) { String key = (String) en.nextElement(); requestMap.put(key, req.getAttribute(key)); } wc.setAttribute("session", sessionMap); req.getSession().setAttribute("protorabbitVersion", version); req.getSession().setAttribute("protorabbitBuildDate", buildDate); wc.setAttribute("request", requestMap); } else { renderEngine = engine; } // buffer the output stream ByteArrayOutputStream bos = new ByteArrayOutputStream(); ICacheable tr = t.getTemplateResource(); resp.setHeader("Content-Type", "text/html"); if (jcfg.profile()) { resp.setHeader("pragma", "NO-CACHE"); resp.setHeader("Cache-Control", "no-cache"); } // get the initial content or get the content if it is expired if ((t.getTimeout(wc) != null && (t.getTimeout(wc) > 0) && ((tr == null || tr.getCacheContext().isExpired()) || t.requiresRefresh(wc) || jcfg.profile() || t.hasUserAgentPropertyDependencies(wc)))) { if (canGzip && t.gzipTemplate(wc) != null && t.gzipTemplate(wc) == true) { resp.setHeader("Vary", "Accept-Encoding"); resp.setHeader("Content-Encoding", "gzip"); } // headers after this point do not get written renderEngine.renderTemplate(id, wc, bos); String content = bos.toString(jcfg.getEncoding()); String hash = IOUtil.generateHash(content); ICacheable cr = new CacheableResource("text/html", t.getTimeout(wc), hash); if (!jcfg.profile()) { resp.setHeader("ETag", cr.getContentHash()); } cr.setContent(new StringBuffer(content)); t.setTemplateResource(cr); if (canGzip && t.gzipTemplate(wc) != null && t.gzipTemplate(wc) == true) { byte[] bytes = cr.getGZippedContent(); cr.incrementGzipAccessCount(); resp.setContentLength(bytes.length); OutputStream out = resp.getOutputStream(); if (bytes != null) { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); bytesServed = bytes.length; IOUtil.writeBinaryResource(bis, out); } } else { OutputStream out = resp.getOutputStream(); byte[] bytes = cr.getContent().toString().getBytes(); cr.incrementAccessCount(); resp.setContentLength(bytes.length); bytesServed = bytes.length; if (bytes != null) { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); IOUtil.writeBinaryResource(bis, out); } } // write out content / gzip or otherwise from the cache } else if (t.getTimeout(wc) != null && t.getTimeout(wc) > 0 && tr != null) { // if the client has the same resource as the one on the server return a 304 // get the If-None-Match header String etag = tr.getContentHash(); String ifNoneMatch = req.getHeader("If-None-Match"); if (etag != null && ifNoneMatch != null && ifNoneMatch.equals(etag)) { resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); if (jcfg.profile()) { profile(wc); } return; } resp.setContentType(tr.getContentType()); if (!jcfg.profile()) { resp.setHeader("ETag", etag); resp.setHeader("Expires", tr.getCacheContext().getExpires()); resp.setHeader("Cache-Control", "public,max-age=" + tr.getCacheContext().getMaxAge()); } if (canGzip && t.gzipTemplate(wc) != null && t.gzipTemplate(wc) == true) { OutputStream out = resp.getOutputStream(); resp.setHeader("Content-Encoding", "gzip"); resp.setHeader("Vary", "Accept-Encoding"); tr.incrementGzipAccessCount(); byte[] bytes = tr.getGZippedContent(); if (bytes != null) { resp.setContentLength(bytes.length); bytesServed = bytes.length; ByteArrayInputStream bis = new ByteArrayInputStream(bytes); IOUtil.writeBinaryResource(bis, out); } } else { OutputStream out = resp.getOutputStream(); tr.incrementAccessCount(); byte[] bytes = tr.getContent().toString().getBytes(); resp.setContentLength(bytes.length); if (bytes != null) { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); bytesServed = bytes.length; IOUtil.writeBinaryResource(bis, out); } } } else { OutputStream out = resp.getOutputStream(); // t.getTemplateResource().incrementAccessCount(); renderEngine.renderTemplate(id, wc, bos); bytesServed = bos.size(); out.write(bos.toByteArray()); } // increment the total template accesses if (t != null) { t.incrementAccessCount(); } if (jcfg.profile()) { profile(wc); } } catch (java.net.SocketException jos) { logger.warning("Got broken pipe. Ignoring..."); return; } finally { if (wc != null) { wc.destroy(); } } long endTime = System.currentTimeMillis(); // add more stats stuff IStat stat = new StatsItem(); stat.setTimestamp(System.currentTimeMillis()); stat.setPath(path); stat.setPathInfo(pathInfo); stat.setRemoteClient(cg.getClientId(req)); stat.setType(StatsItem.types.VIEW); stat.setRequestURI(req.getRequestURI()); stat.setProcessTime(new Long(endTime - iStartTime)); stat.setContentLength(new Long(bytesServed)); stat.setContentType("text/html"); statsManager.add(stat); }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/contact", method = RequestMethod.POST) public final ModelAndView sendMessage(@ModelAttribute("message") final EmailMessage message, final BindingResult bindResult) { final String methodName = CommonController.CNAME + "#sendMessage(@ModelAttribute(\"message\") final EmailMessage message, final BindingResult bindResult)"; if (DEBUG) {/*ww w . j a v a2s . c o m*/ DEBUGGER.debug(methodName); DEBUGGER.debug("EmailMessage: {}", message); DEBUGGER.debug("BindingResult: {}", bindResult); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Session ID: {}", hSession.getId()); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } // validate this.appConfig.getEmailValidator().validate(message, bindResult); if (bindResult.hasErrors()) { // errors occurred during validation ERROR_RECORDER.error("Form failed field validation"); mView.addObject(Constants.ERROR_MESSAGE, this.appConfig.getMessageValidationFailed()); mView.addObject("command", new EmailMessage()); mView.setViewName(this.appConfig.getContactPage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; } this.appConfig.getMessageValidator().validate(message, bindResult); if (bindResult.hasErrors()) { // errors occurred during validation ERROR_RECORDER.error("Form failed field validation"); mView = new ModelAndView(); mView.addObject(Constants.ERROR_MESSAGE, this.appConfig.getMessageValidationFailed()); mView.addObject("command", new EmailMessage()); mView.setViewName(this.appConfig.getContactPage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; } try { EmailUtils.sendEmailMessage(message, true); EmailMessage autoResponse = new EmailMessage(); autoResponse.setIsAlert(false); autoResponse.setMessageSubject(this.contactResponseEmail.getSubject()); autoResponse.setMessageTo(new ArrayList<>(Arrays .asList(String.format(this.contactResponseEmail.getTo()[0], message.getEmailAddr().get(0))))); autoResponse.setEmailAddr( new ArrayList<>(Arrays.asList(String.format(this.contactResponseEmail.getFrom())))); autoResponse.setMessageBody(String.format(this.contactResponseEmail.getText(), message.getEmailAddr(), message.getMessageBody())); if (DEBUG) { DEBUGGER.debug("EmailMessage: {}", autoResponse); } EmailUtils.sendEmailMessage(autoResponse, true); mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getRequestCompletePage()); } catch (MessagingException msx) { ERROR_RECORDER.error(msx.getMessage(), msx); mView.setViewName(this.appConfig.getErrorResponsePage()); } if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:com.cws.esolutions.security.filters.SessionAuthenticationFilter.java
public void doFilter(final ServletRequest sRequest, final ServletResponse sResponse, final FilterChain filterChain) throws IOException, ServletException { final String methodName = SessionAuthenticationFilter.CNAME + "#doFilter(final ServletRequest sRequest, final ServletResponse sResponse, final FilterChain filterChain) throws IOException, ServletException"; if (DEBUG) {//from w ww . j a v a 2 s . c om DEBUGGER.debug(methodName); DEBUGGER.debug("ServletRequest: {}", sRequest); DEBUGGER.debug("ServletResponse: {}", sResponse); } final HttpServletRequest hRequest = (HttpServletRequest) sRequest; final HttpServletResponse hResponse = (HttpServletResponse) sResponse; final HttpSession hSession = hRequest.getSession(false); final String requestURI = hRequest.getRequestURI(); final String passwdPage = hRequest.getContextPath() + this.passwordURI; final StringBuilder redirectPath = new StringBuilder().append(hRequest.getContextPath() + this.loginURI) .append("?vpath=" + requestURI); if (DEBUG) { DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpServletResponse: {}", hResponse); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("RequestURI: {}", requestURI); DEBUGGER.debug("passwdPage: {}", passwdPage); DEBUGGER.debug("redirectPath: {}", redirectPath); DEBUGGER.debug("Dumping session content:"); Enumeration<?> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String element = (String) sessionEnumeration.nextElement(); Object value = hSession.getAttribute(element); DEBUGGER.debug("Attribute: {}; Value: {}", element, value); } DEBUGGER.debug("Dumping request content:"); Enumeration<?> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String element = (String) requestEnumeration.nextElement(); Object value = hRequest.getAttribute(element); DEBUGGER.debug("Attribute: {}; Value: {}", element, value); } DEBUGGER.debug("Dumping request parameters:"); Enumeration<?> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String element = (String) paramsEnumeration.nextElement(); Object value = hRequest.getParameter(element); DEBUGGER.debug("Parameter: {}; Value: {}", element, value); } } if (StringUtils.equals(this.loginURI, requestURI)) { if (DEBUG) { DEBUGGER.debug("Request authenticated. No action taken !"); } filterChain.doFilter(sRequest, sResponse); return; } if ((this.ignoreURIs != null) && (this.ignoreURIs.length != 0)) { if (Arrays.asList(this.ignoreURIs).contains("ALL")) { if (DEBUG) { DEBUGGER.debug("ALL URIs are ignored. Breaking ..."); } filterChain.doFilter(sRequest, sResponse); return; } // hostname isnt in ignore list for (String uri : this.ignoreURIs) { uri = hRequest.getContextPath().trim() + uri.trim(); if (DEBUG) { DEBUGGER.debug(uri); DEBUGGER.debug(requestURI); } if (StringUtils.contains(requestURI, uri)) { // ignore if (DEBUG) { DEBUGGER.debug("URI matched to ignore list - breaking out"); } filterChain.doFilter(sRequest, sResponse); return; } } } if (hRequest.isRequestedSessionIdFromURL()) { ERROR_RECORDER.error("Session found is from URL. Redirecting request to " + hRequest.getContextPath() + this.loginURI); // invalidate the session hRequest.getSession(false).invalidate(); hSession.removeAttribute(SessionAuthenticationFilter.USER_ACCOUNT); hSession.invalidate(); hResponse.sendRedirect(hRequest.getContextPath() + this.loginURI); return; } Enumeration<?> sessionAttributes = hSession.getAttributeNames(); if (DEBUG) { DEBUGGER.debug("Enumeration<String>: {}", sessionAttributes); } while (sessionAttributes.hasMoreElements()) { String element = (String) sessionAttributes.nextElement(); if (DEBUG) { DEBUGGER.debug("element: {}", element); } Object value = hSession.getAttribute(element); if (DEBUG) { DEBUGGER.debug("sessionValue: {}", value); } if (value instanceof UserAccount) { UserAccount userAccount = (UserAccount) value; if (DEBUG) { DEBUGGER.debug("UserAccount: {}", userAccount); } if (userAccount.getStatus() != null) { switch (userAccount.getStatus()) { case EXPIRED: if ((!(StringUtils.equals(requestURI, passwdPage)))) { ERROR_RECORDER.error( "Account is expired and this request is not for the password page. Redirecting !"); hResponse.sendRedirect(hRequest.getContextPath() + this.passwordURI); return; } filterChain.doFilter(sRequest, sResponse); return; case RESET: if ((!(StringUtils.equals(requestURI, passwdPage)))) { ERROR_RECORDER.error( "Account has status RESET and this request is not for the password page. Redirecting !"); hResponse.sendRedirect(hRequest.getContextPath() + this.passwordURI); return; } filterChain.doFilter(sRequest, sResponse); return; case SUCCESS: filterChain.doFilter(sRequest, sResponse); return; default: break; } } } } // no user account in the session ERROR_RECORDER.error("Session contains no existing user account. Redirecting request to " + hRequest.getContextPath() + this.loginURI); // invalidate the session hSession.removeAttribute(SessionAuthenticationFilter.USER_ACCOUNT); hSession.invalidate(); if (StringUtils.isNotEmpty(hRequest.getQueryString())) { redirectPath.append("?" + hRequest.getQueryString()); } if (DEBUG) { DEBUGGER.debug("redirectPath: {}", redirectPath.toString()); } hResponse.sendRedirect(URLEncoder.encode(redirectPath.toString(), systemConfig.getEncoding())); return; }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/default", method = RequestMethod.GET) public final ModelAndView showDefaultPage() { final String methodName = CommonController.CNAME + "#showDefaultPage()"; if (DEBUG) {/* w w w . j a va 2 s .c o m*/ DEBUGGER.debug(methodName); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); final String lang = hRequest.getParameter(Constants.PARAMETER_LANG); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("lang: {}", lang); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } try { ProductRequest productRequest = new ProductRequest(); productRequest.setIsFeatured(true); productRequest.setLang((StringUtils.isBlank(lang)) ? "en" : lang); if (DEBUG) { DEBUGGER.debug("ProductRequest: {}", productRequest); } ProductResponse productResponse = this.productRefSvc.getFeaturedProducts(productRequest); if (DEBUG) { DEBUGGER.debug("ProductResponse: {}", productResponse); } if (productResponse.getRequestStatus() == CoreServicesStatus.SUCCESS) { List<Product> featuredProducts = productResponse.getProductList(); if (DEBUG) { DEBUGGER.debug("List<Product>: {}", featuredProducts); } mView.addObject("featuredProducts", featuredProducts); } } catch (ProductRequestException prx) { ERROR_RECORDER.error(prx.getMessage(), prx); mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getErrorResponsePage()); } mView.setViewName(this.appConfig.getHomePage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/search/terms/{terms}page/{page}", method = RequestMethod.GET) public final ModelAndView siteSearch(@PathVariable("terms") final String terms, @PathVariable("page") final int page) { final String methodName = CommonController.CNAME + "#siteSearch(@PathVariable(\"terms\") final String terms, @PathVariable(\"page\") final int page)"; if (DEBUG) {//from ww w .j a v a 2 s .c o m DEBUGGER.debug(methodName); DEBUGGER.debug("terms: {}", terms); DEBUGGER.debug("page: {}", page); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); final ISearchProcessor processor = new SearchProcessorImpl(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Session ID: {}", hSession.getId()); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } try { SearchRequest request = new SearchRequest(); request.setSearchType(SearchRequestType.SITE); request.setSearchTerms(terms); request.setStartRow(page); if (DEBUG) { DEBUGGER.debug("SearchRequest: {}", request); } SearchResponse response = processor.doSiteSearch(request); if (DEBUG) { DEBUGGER.debug("SearchResponse: {}", response); } if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) { mView.addObject("pages", (int) Math.ceil(response.getEntryCount() * 1.0 / this.recordsPerPage)); mView.addObject("page", page); mView.addObject("searchTerms", terms); mView.addObject("searchResults", response.getResults()); mView.setViewName(this.appConfig.getSearchRequestPage()); } else { mView.addObject(Constants.MESSAGE_RESPONSE, response.getResponse()); mView.setViewName(this.appConfig.getSearchRequestPage()); } mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getRequestCompletePage()); } catch (SearchRequestException srx) { ERROR_RECORDER.error(srx.getMessage(), srx); mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getErrorResponsePage()); } if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/search", method = RequestMethod.POST) public final ModelAndView siteSearch(@ModelAttribute("request") final SearchRequest request, final BindingResult bindResult) { final String methodName = CommonController.CNAME + "#sendMessage(@ModelAttribute(\"request\") final SearchRequest request, final BindingResult bindResult)"; if (DEBUG) {//from w w w.j a v a 2 s . c om DEBUGGER.debug(methodName); DEBUGGER.debug("SearchRequest: {}", request); DEBUGGER.debug("BindingResult: {}", bindResult); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); final ISearchProcessor processor = new SearchProcessorImpl(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Session ID: {}", hSession.getId()); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } // validate this.appConfig.getEmailValidator().validate(request, bindResult); if (bindResult.hasErrors()) { // errors occurred during validation ERROR_RECORDER.error("Form failed field validation"); mView.addObject(Constants.ERROR_MESSAGE, this.appConfig.getMessageValidationFailed()); mView.addObject("command", new SearchRequest()); mView.setViewName(this.appConfig.getSearchRequestPage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; } try { SearchResponse response = processor.doSiteSearch(request); if (DEBUG) { DEBUGGER.debug("SearchResponse: {}", response); } if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) { mView.addObject("pages", (int) Math.ceil(response.getEntryCount() * 1.0 / this.recordsPerPage)); mView.addObject("page", 1); mView.addObject("searchTerms", request.getSearchTerms()); mView.addObject("searchResults", response.getResults()); mView.setViewName(this.appConfig.getSearchRequestPage()); } else { mView.addObject(Constants.MESSAGE_RESPONSE, response.getResponse()); mView.setViewName(this.appConfig.getSearchRequestPage()); } mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getRequestCompletePage()); } catch (SearchRequestException srx) { ERROR_RECORDER.error(srx.getMessage(), srx); mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getErrorResponsePage()); } if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }