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.kmnet.com.fw.web.token.transaction.HttpSessionTransactionTokenStore.java
/** * Creates a new Token key and reserve it in the HttpSession<br> * removes oldeset token if token size is greater than or equals {@link #transactionTokensPerTokenName} in the same * namespace.//from w w w .j av a2 s . c o m * @see org.kmnet.com.fw.web.token.transaction.TransactionTokenStore#createAndReserveTokenKey(java.lang.String) */ @Override public String createAndReserveTokenKey(String tokenName) { String tokenNamePrefix = TOKEN_HOLDER_SESSION_ATTRIBUTE_PREFIX + tokenName; Set<String> sessionAttributeNames = new HashSet<String>(); HttpSession session = getSession(); Object mutex = getMutex(session); String tokenKey = null; synchronized (mutex) { Enumeration<String> tokenNameEnumeration = session.getAttributeNames(); while (tokenNameEnumeration.hasMoreElements()) { String name = tokenNameEnumeration.nextElement(); // fetch the sessionKeyPrefix (session key with only Token prefix and namespace name) and compare if (tokenNamePrefix.equals(name.split(TransactionToken.TOKEN_STRING_SEPARATOR)[0])) { sessionAttributeNames.add(name); } } for (int i = 0, max = sessionAttributeNames.size(); i < max; i++) { // do not use while loop to avoid infinite loop if (sessionAttributeNames.size() >= transactionTokensPerTokenName) { String oldestTokenName = null; TokenHolder oldestTokenHolder = new TokenHolder(null, Long.MAX_VALUE); for (String name : sessionAttributeNames) { TokenHolder tokenHolder = (TokenHolder) session.getAttribute(name); if (tokenHolder.getTimestamp() < oldestTokenHolder.getTimestamp()) { oldestTokenName = name; oldestTokenHolder = tokenHolder; } } session.removeAttribute(oldestTokenName); sessionAttributeNames.remove(oldestTokenName); } else { break; } } for (int i = 0; i < retryCreateTokenName; i++) { String str = generator.generate(session.getId()); String name = tokenNamePrefix + TransactionToken.TOKEN_STRING_SEPARATOR + str; if (!sessionAttributeNames.contains(name)) { tokenKey = str; break; } } } if (tokenKey == null) { throw new IllegalStateException( "token key generation failed within retry count " + retryCreateTokenName); } return tokenKey; }
From source file:com.adito.boot.Util.java
/** * Dump all session attributes to {@link System#err}. * /* ww w . j a v a 2 s . co m*/ * @param session session to get attributes from */ public static void dumpSessionAttributes(HttpSession session) { System.err.println("Session attributes for " + session.getId()); for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) { String n = (String) e.nextElement(); System.err.println(" " + n + " = " + session.getAttribute(n)); } }
From source file:org.apache.cocoon.servlet.DebugFilter.java
/** * Log debug information about the current environment. * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) *///from ww w. j a v a2 s. c o m public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { // we don't do debug msgs if this is not a http servlet request if (!(req instanceof HttpServletRequest)) { filterChain.doFilter(req, res); return; } try { ++activeRequestCount; final HttpServletRequest request = (HttpServletRequest) req; if (getLogger().isDebugEnabled()) { final StringBuffer msg = new StringBuffer(); msg.append("DEBUGGING INFORMATION:").append(lineSeparator); msg.append("REQUEST: ").append(request.getRequestURI()).append(lineSeparator).append(lineSeparator); msg.append("CONTEXT PATH: ").append(request.getContextPath()).append(lineSeparator); msg.append("SERVLET PATH: ").append(request.getServletPath()).append(lineSeparator); msg.append("PATH INFO: ").append(request.getPathInfo()).append(lineSeparator).append(lineSeparator); msg.append("REMOTE HOST: ").append(request.getRemoteHost()).append(lineSeparator); msg.append("REMOTE ADDRESS: ").append(request.getRemoteAddr()).append(lineSeparator); msg.append("REMOTE USER: ").append(request.getRemoteUser()).append(lineSeparator); msg.append("REQUEST SESSION ID: ").append(request.getRequestedSessionId()).append(lineSeparator); msg.append("REQUEST PREFERRED LOCALE: ").append(request.getLocale().toString()) .append(lineSeparator); msg.append("SERVER HOST: ").append(request.getServerName()).append(lineSeparator); msg.append("SERVER PORT: ").append(request.getServerPort()).append(lineSeparator) .append(lineSeparator); msg.append("METHOD: ").append(request.getMethod()).append(lineSeparator); msg.append("CONTENT LENGTH: ").append(request.getContentLength()).append(lineSeparator); msg.append("PROTOCOL: ").append(request.getProtocol()).append(lineSeparator); msg.append("SCHEME: ").append(request.getScheme()).append(lineSeparator); msg.append("AUTH TYPE: ").append(request.getAuthType()).append(lineSeparator).append(lineSeparator); msg.append("CURRENT ACTIVE REQUESTS: ").append(activeRequestCount).append(lineSeparator); // log all of the request parameters final Enumeration e = request.getParameterNames(); msg.append("REQUEST PARAMETERS:").append(lineSeparator).append(lineSeparator); while (e.hasMoreElements()) { String p = (String) e.nextElement(); msg.append("PARAM: '").append(p).append("' ").append("VALUES: '"); String[] params = request.getParameterValues(p); for (int i = 0; i < params.length; i++) { msg.append("[" + params[i] + "]"); if (i != (params.length - 1)) { msg.append(", "); } } msg.append("'").append(lineSeparator); } // log all of the header parameters final Enumeration e2 = request.getHeaderNames(); msg.append("HEADER PARAMETERS:").append(lineSeparator).append(lineSeparator); while (e2.hasMoreElements()) { String p = (String) e2.nextElement(); msg.append("PARAM: '").append(p).append("' ").append("VALUES: '"); Enumeration e3 = request.getHeaders(p); while (e3.hasMoreElements()) { msg.append("[" + e3.nextElement() + "]"); if (e3.hasMoreElements()) { msg.append(", "); } } msg.append("'").append(lineSeparator); } msg.append(lineSeparator).append("SESSION ATTRIBUTES:").append(lineSeparator).append(lineSeparator); // log all of the session attributes final HttpSession session = ((HttpServletRequest) req).getSession(false); if (session != null) { // Fix bug #12139: Session can be modified while still // being enumerated here synchronized (session) { final Enumeration se = session.getAttributeNames(); while (se.hasMoreElements()) { String p = (String) se.nextElement(); msg.append("PARAM: '").append(p).append("' ").append("VALUE: '") .append(session.getAttribute(p)).append("'").append(lineSeparator); } } } getLogger().debug(msg.toString()); } // Delegate filterChain.doFilter(request, res); } finally { --activeRequestCount; } }
From source file:edu.harvard.i2b2.fhir.oauth2.ws.OAuth2AuthzEndpoint.java
@Path("processScope") @GET// w w w . j a v a 2s .c om public Response processResourceOwnerScopeChoice(@Context HttpServletRequest request) { try { logger.trace("processing scope: sessionid:" + request.getSession().getId()); // save scope to session and // redirect to client uri HttpSession session = request.getSession(); session.setAttribute("permittedScopes", "user/*.*"); String msg = ""; Enumeration x = session.getAttributeNames(); while (x.hasMoreElements()) { String p = (String) x.nextElement(); msg = msg + p + "=" + session.getAttribute(p).toString() + "\n"; } logger.trace("sessionAttributes:" + msg); // create AuthToken in Database; String pmResponseXml = (String) session.getAttribute("pmResponseXml"); if (pmResponseXml == null) throw new RuntimeException("PMRESPONSE NOT FOUND"); String resourceUserId = (String) session.getAttribute("i2b2User"); String i2b2Token = (String) I2b2Util.getToken(pmResponseXml); String authorizationCode = (String) session.getAttribute("authorizationCode"); String clientRedirectUri = (String) session.getAttribute("redirectUri"); String clientId = (String) session.getAttribute("clientId"); String i2b2Project = (String) session.getAttribute("i2b2Project"); String state = (String) session.getAttribute("state"); String patientId = (String) session.getAttribute("patientId"); HashSet<String> scopeHashSet = (HashSet<String>) session.getAttribute("scope"); String scope = ""; for (String s : scopeHashSet) { scope += "," + s; } scope = scope.substring(1); logger.debug(">>scopeHS=" + scopeHashSet.toString()); //String scope = "user/*.*";//(String) session.getAttribute("scope");//"user/*.*";// AuthToken authToken = authTokenBean.find(authorizationCode); if (authToken == null) authToken = authTokenBean.createAuthToken(authorizationCode, resourceUserId, i2b2Token, clientRedirectUri, clientId, state, scope, i2b2Project, patientId); session.setAttribute("msg", ""); //String finalUri = successfulResponse((HttpServletRequest) session.getAttribute("request"),scope,patientId,state); String finalUri = (String) session.getAttribute("finalUri"); //+"&patient="+patientId.trim() +"&scope="+patientId.trim(); logger.trace("finalUri:" + finalUri); return Response.status(Status.MOVED_PERMANENTLY).location(new URI(finalUri)) .header("session_id", session.getId()).build(); } catch (Exception e) { logger.error(e.getMessage(), e); e.printStackTrace(); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } }
From source file:org.wso2.carbon.ui.AbstractCarbonUIAuthenticator.java
/** * Regenerates session id after each login attempt. * @param request//from w ww.j ava2 s .com */ private void regenrateSession(HttpServletRequest request) { HttpSession oldSession = request.getSession(); Enumeration attrNames = oldSession.getAttributeNames(); Properties props = new Properties(); while (attrNames != null && attrNames.hasMoreElements()) { String key = (String) attrNames.nextElement(); props.put(key, oldSession.getAttribute(key)); } oldSession.invalidate(); HttpSession newSession = request.getSession(true); attrNames = props.keys(); while (attrNames != null && attrNames.hasMoreElements()) { String key = (String) attrNames.nextElement(); newSession.setAttribute(key, props.get(key)); } }
From source file:de.betterform.agent.web.servlet.XFormsRepeater.java
protected void doSubmissionReplaceAll(HttpServletRequest request, HttpServletResponse response) throws IOException { final Log LOG = LogFactory.getLog(XFormsRepeater.class); HttpSession session = request.getSession(false); WebProcessor webProcessor = WebUtil.getWebProcessor(request, response, session); if (session != null && webProcessor != null) { if (LOG.isDebugEnabled()) { Enumeration keys = session.getAttributeNames(); if (keys.hasMoreElements()) { LOG.debug("--- existing keys in session --- "); }/* w w w . j a v a 2 s. c om*/ while (keys.hasMoreElements()) { String s = (String) keys.nextElement(); LOG.debug("existing sessionkey: " + s + ":" + session.getAttribute(s)); } } Map submissionResponse = webProcessor.checkForExitEvent().getContextInfo(); if (submissionResponse != null) { if (LOG.isDebugEnabled()) { LOG.debug("handling submission/@replace='all'"); Enumeration keys = session.getAttributeNames(); if (keys.hasMoreElements()) { LOG.debug("--- existing keys in http session --- "); while (keys.hasMoreElements()) { String s = (String) keys.nextElement(); LOG.debug("existing sessionkey: " + s + ":" + session.getAttribute(s)); } } else { LOG.debug("--- no keys left in http session --- "); } } // copy header fields Map headerMap = (Map) submissionResponse.get("header"); String name; String value; Iterator iterator = headerMap.keySet().iterator(); while (iterator.hasNext()) { name = (String) iterator.next(); if (name.equalsIgnoreCase("Transfer-Encoding")) { // Some servers (e.g. WebSphere) may set a "Transfer-Encoding" // with the value "chunked". This may confuse the client since // XFormsServlet output is not encoded as "chunked", so this // header is ignored. continue; } value = (String) headerMap.get(name); if (LOG.isDebugEnabled()) { LOG.debug("added header: " + name + "=" + value); } response.setHeader(name, value); } // copy body stream InputStream bodyStream = (InputStream) submissionResponse.get("body"); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); for (int b = bodyStream.read(); b > -1; b = bodyStream.read()) { outputStream.write(b); } // close streams bodyStream.close(); outputStream.close(); //kill XFormsSession WebUtil.removeSession(webProcessor.getKey()); return; } } response.sendError(HttpServletResponse.SC_FORBIDDEN, "no submission response available"); }
From source file:edu.harvard.i2b2.fhirserver.ws.OAuth2AuthzEndpoint.java
@Path("processScope") @POST/*from ww w. j av a 2s .co m*/ public Response processResourceOwnerScopeChoice(@FormParam("project") String i2b2Project, @Context HttpServletRequest request) { try { logger.trace("processing scope:" + i2b2Project + " sessionid:" + request.getSession().getId()); // save scope to session and // redirect to client uri HttpSession session = request.getSession(); session.setAttribute("permittedScopes", "user/*.*"); String finalUri = (String) session.getAttribute("finalUri"); String msg = ""; Enumeration x = session.getAttributeNames(); while (x.hasMoreElements()) { String p = (String) x.nextElement(); msg = msg + p + "=" + session.getAttribute(p).toString() + "\n"; } logger.trace("sessionAttributes:" + msg); // create AuthToken in Database; String pmResponseXml = (String) session.getAttribute("pmResponseXml"); if (pmResponseXml == null) throw new RuntimeException("PMRESPONSE NOT FOUND"); String resourceUserId = (String) session.getAttribute("resourceUserId"); String i2b2Token = (String) I2b2Util.getToken(pmResponseXml); String authorizationCode = (String) session.getAttribute("authorizationCode"); String clientRedirectUri = (String) session.getAttribute("redirectUri"); String clientId = (String) session.getAttribute("clientId"); String state = (String) session.getAttribute("state"); String scope = "user/*.*";// HashSet<String> // session.getAttribute("scope"); AuthToken authToken = authTokenBean.find(authorizationCode); if (authToken == null) authToken = authTokenBean.createAuthToken(authorizationCode, resourceUserId, i2b2Token, clientRedirectUri, clientId, state, scope, i2b2Project); session.setAttribute("msg", ""); return Response.status(Status.MOVED_PERMANENTLY).location(new URI(finalUri)) .header("session_id", session.getId()).build(); } catch (Exception e) { logger.error(e.getMessage(), e); e.printStackTrace(); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } }
From source file:org.grails.gsp.jsp.GroovyPagesPageContext.java
@SuppressWarnings("rawtypes") @Override/*from ww w .ja v a 2s. c o m*/ public Enumeration getAttributeNamesInScope(int scope) { switch (scope) { case PAGE_SCOPE: final Iterator i = pageScope.getVariables().keySet().iterator(); return new Enumeration() { @Override public boolean hasMoreElements() { return i.hasNext(); } @Override public Object nextElement() { return i.next(); } }; case REQUEST_SCOPE: return request.getAttributeNames(); case SESSION_SCOPE: HttpSession httpSession = request.getSession(false); if (httpSession != null) { return httpSession.getAttributeNames(); } else { return EMPTY_ENUMERATION; } case APPLICATION_SCOPE: return servletContext.getAttributeNames(); } return EMPTY_ENUMERATION; }
From source file:com.cws.us.pws.controllers.ServicesController.java
@RequestMapping(value = "/default", method = RequestMethod.GET) public final ModelAndView showDefaultPage() { final String methodName = ServicesController.CNAME + "#showDefaultPage()"; if (DEBUG) {/*from w w w.j a v a 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(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); 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.setViewName(this.defaultPage); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:org.tolven.restful.AccountResourcesV0.java
/** * Get general information about the current account for the current user * @return/*from w w w . jav a 2 s . c o m*/ */ @Path("info") @GET @Produces(MediaType.TEXT_PLAIN) public String getInfo() { HttpSession session = request.getSession(); StringBuffer sb = new StringBuffer(); sb.append("Session Attributes:\n"); for (Enumeration<String> e = session.getAttributeNames(); e.hasMoreElements();) { String attr = e.nextElement(); sb.append(" "); sb.append(attr); sb.append("="); sb.append(session.getAttribute(attr)); sb.append("\n"); } Long accountUserId = (Long) session.getAttribute("accountUserId"); if (accountUserId != null) { sb.append("\nUser Attributes:\n"); AccountUser accountUser = activationBean.findAccountUser(accountUserId); TolvenPerson tp = getTolvenPerson(); sb.append(" UID="); sb.append(tp.getUid()); sb.append("\n"); sb.append(" GivenName="); sb.append(tp.getGivenName()); sb.append("\n"); sb.append(" SN="); sb.append(tp.getSn()); sb.append("\n"); try { sb.append(" email="); sb.append(tp.getPrimaryMail()); sb.append("\n"); } catch (Exception e) { sb.append("Exception: " + e.getMessage()); } sb.append("\nAccount Attributes:\n"); Account account = accountUser.getAccount(); sb.append(" accountId="); sb.append(account.getId()); sb.append("\n"); sb.append(" Title="); sb.append(account.getTitle()); sb.append("\n"); { Account accountTemplate = account.getAccountTemplate(); if (accountTemplate != null) { sb.append(" templateAccountId="); sb.append(accountTemplate.getId()); sb.append("\n"); } } } return sb.toString(); }