List of usage examples for javax.servlet.http HttpSession getId
public String getId();
From source file:de.hybris.eventtracking.ws.services.DefaultRawEventEnricher.java
/** * @see de.hybris.eventtracking.ws.services.RawEventEnricher#enrich(java.lang.String, * javax.servlet.http.HttpServletRequest) *//*from w w w . j a va 2s. c o m*/ @Override public String enrich(final String json, final HttpServletRequest req) { final HttpSession session = req.getSession(); final String sessionId = session.getId(); final String timestamp = Integer.toString(Math.round(System.currentTimeMillis() / 1000)); // seconds since Unix epoch final UserModel user = userService.getCurrentUser(); String userId = null; String userEmail = null; if (user != null && CustomerModel.class.isAssignableFrom(user.getClass())) { userId = ((CustomerModel) user).getCustomerID(); userEmail = ((CustomerModel) user).getContactEmail(); } userId = StringUtils.trimToEmpty(userId); userEmail = StringUtils.trimToEmpty(userEmail); final Chainr chainr = Chainr.fromSpec(JsonUtils .jsonToList(String.format(ENRICHMENT_SPEC_TEMPLATE, sessionId, timestamp, userId, userEmail))); Map<String, Object> jsonObjectMap; try { jsonObjectMap = JsonUtils.javason(json); } catch (final IOException e) { throw new RuntimeException(e); } return JsonUtils.toJsonString(chainr.transform(jsonObjectMap)); }
From source file:com.boundlessgeo.geoserver.api.controllers.LoginController.java
/** * API endpoint for determining if a user is logged in * /* ww w. j av a 2 s . com*/ * @param req HTTP request * @param res HTTP response * @return JSON object containing the session id, the session timeout interval, * and the GeoServer user, if applicable. */ @RequestMapping() public @ResponseBody JSONObj handle(HttpServletRequest req, HttpServletResponse res) { JSONObj obj = new JSONObj(); HttpSession session = req.getSession(false); if (session != null) { obj.put("session", session.getId()); obj.put("timeout", session.getMaxInactiveInterval()); } Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Object principal = auth.getPrincipal(); if (principal instanceof GeoServerUser) { GeoServerUser user = (GeoServerUser) principal; obj.put("user", user.getUsername()); //PKI Authentication } else if (auth instanceof PreAuthenticatedAuthenticationToken && principal instanceof String) { obj.put("user", principal); } return obj; }
From source file:com.boundlessgeo.geoserver.api.controllers.SessionsController.java
@RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd'T'HH:mm:ssZ"); JSONArr arr = new JSONArr(); for (HttpSession session : AppSessionDebugger.list()) { JSONObj obj = arr.addObject();/* w w w . ja v a2 s . com*/ obj.put("id", session.getId()).put("created", dateFormat.format(new Date(session.getCreationTime()))) .put("updated", dateFormat.format(new Date(session.getLastAccessedTime()))) .put("timeout", session.getMaxInactiveInterval()); @SuppressWarnings("unchecked") Enumeration<String> attNames = session.getAttributeNames(); JSONObj atts = obj.putObject("attributes"); while (attNames.hasMoreElements()) { String attName = attNames.nextElement(); atts.put(attName, session.getAttribute(attName).toString()); } } return arr; }
From source file:com.netspective.sparx.navigate.query.DefaultQueryResultsNavigatorStatesManager.java
public String getQueryResultsSessionAttrKey(final QueryResultsNavigatorPage page, final HttpSession session) { return page.getQualifiedName() + "/" + session.getId(); }
From source file:org.apache.syncope.core.misc.security.SyncopeAuthenticationDetails.java
public SyncopeAuthenticationDetails(final HttpServletRequest request) { this.remoteAddress = request.getRemoteAddr(); HttpSession session = request.getSession(false); this.sessionId = session == null ? null : session.getId(); this.domain = request.getHeader(RESTHeaders.DOMAIN); }
From source file:org.zht.framework.interceptors.TokenInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { super.afterCompletion(request, response, handler, ex); HttpSession session = request.getSession(false); if (session != null) { String seesionId = session.getId(); String uri = request.getRequestURI(); session.removeAttribute("_Token" + seesionId + uri); }/*from ww w . j ava 2 s . c om*/ }
From source file:org.zht.framework.interceptors.TokenInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { HttpSession session = request.getSession(false); if (session != null) { String seesionId = session.getId(); String uri = request.getRequestURI(); session.removeAttribute("_Token" + seesionId + uri); }/*from www. j a v a 2 s.c o m*/ super.postHandle(request, response, handler, modelAndView); }
From source file:jp.terasoluna.fw.web.HttpSessionListenerImpl.java
/** * <p>HTTPZbVCxg???B</p>/*from w w w . ja v a2 s. co m*/ * <p> * ZbVRtfBNg * ??A???B * </p> * * @param event ZbVCxg */ public void sessionDestroyed(HttpSessionEvent event) { if (log.isDebugEnabled()) { log.debug("session destroyed."); } HttpSession session = event.getSession(); File dir = FileUtil.getSessionDirectory(session.getId()); if (dir.exists() && dir.isDirectory()) { if (FileUtil.removeSessionDirectory(session.getId())) { log.debug("\"" + dir.getPath() + "\" removed."); } else { log.error("can't remove \"" + dir.getPath() + "\"."); } } }
From source file:org.owasp.webgoat.service.SessionService.java
/** * Returns hints for current lesson/* ww w . j a va 2s . c om*/ * * @param session a {@link javax.servlet.http.HttpSession} object. * @param request a {@link javax.servlet.http.HttpServletRequest} object. * @return a {@link java.lang.String} object. */ @RequestMapping(value = "/session.mvc", produces = "application/json") public @ResponseBody String showSession(HttpServletRequest request, HttpSession session) { StringBuilder sb = new StringBuilder(); sb.append("id").append(" = ").append(session.getId()).append("\n"); sb.append("created").append(" = ").append(new Date(session.getCreationTime())).append("\n"); sb.append("last access").append(" = ").append(new Date(session.getLastAccessedTime())).append("\n"); sb.append("timeout (secs)").append(" = ").append(session.getMaxInactiveInterval()).append("\n"); sb.append("session from cookie?").append(" = ").append(request.isRequestedSessionIdFromCookie()) .append("\n"); sb.append("session from url?").append(" = ").append(request.isRequestedSessionIdFromURL()).append("\n"); sb.append("=====================================\n"); // get attributes List<String> attributes = new ArrayList<String>(); Enumeration keys = session.getAttributeNames(); while (keys.hasMoreElements()) { String name = (String) keys.nextElement(); attributes.add(name); } Collections.sort(attributes); for (String attribute : attributes) { String value = session.getAttribute(attribute) + ""; sb.append(attribute).append(" = ").append(value).append("\n"); } return sb.toString(); }
From source file:be.fedict.eid.idp.webapp.SessionLoggingFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpSession httpSession = httpRequest.getSession(false); if (null != httpSession) { String sessionId = httpSession.getId(); boolean isNew = httpSession.isNew(); String clientSessionId = httpRequest.getRequestedSessionId(); LOG.debug("request URI: " + httpRequest.getRequestURI()); LOG.debug("session id: " + sessionId + "; is new: " + isNew); if (null == clientSessionId) { LOG.debug("no client session id received"); } else {/*from ww w. j a v a 2 s . c o m*/ LOG.debug("client session id: " + clientSessionId); } } chain.doFilter(request, response); }