List of usage examples for javax.servlet.http HttpSession getAttribute
public Object getAttribute(String name);
null
if no object is bound under the name. From source file:com.onehippo.gogreen.login.HstConcurrentLoginFilter.java
static void unregisterUserSession(HttpSession session) { String username = (String) session.getAttribute(USERNAME_ATTR); log.debug("HstConcurrentLoginFilter will unregister session for {}", username); if (username == null) { return;//from ww w. j a v a2 s . c o m } ServletContext servletContext = session.getServletContext(); @SuppressWarnings("unchecked") Map<String, HttpSessionWrapper> map = (Map<String, HttpSessionWrapper>) servletContext .getAttribute(USERNAME_SESSIONID_MAP_ATTR); if (map != null) { HttpSessionWrapper oldHttpSessionWrapper = null; synchronized (map) { oldHttpSessionWrapper = map.get(username); if (oldHttpSessionWrapper != null) { if (oldHttpSessionWrapper.equalsTo(session)) { map.remove(username); log.debug("HstConcurrentLoginFilter kicked out session ({}) for {}.", oldHttpSessionWrapper.getId(), username); } else { log.debug( "HstConcurrentLoginFilter didn't kick out session ({}) for {} because it's logged on by other http session.", oldHttpSessionWrapper.getId(), username); } } } } else { log.error("HstConcurrentLoginFilter is in invalid state. The session ids map is not found."); } session.removeAttribute(USERNAME_ATTR); log.debug("HstConcurrentLoginFilter removed user name session attribute: {}", username); }
From source file:net.sourceforge.vulcan.web.struts.actions.ProjectReportBaseAction.java
static PreferencesDto findPreferences(HttpServletRequest request) { final HttpSession session = request.getSession(false); if (session != null) { final PreferencesDto prefs = (PreferencesDto) session.getAttribute(Keys.PREFERENCES); if (prefs != null) { return prefs; }// ww w.ja v a2s . c om } return (PreferencesDto) request.getAttribute(Keys.PREFERENCES); }
From source file:tools.EpsServletUtilities.java
protected static void registerChartForDeletion(File tempFile, HttpSession session) { // Add chart to deletion list in session if (session != null) { EpsDeleter chartDeleter = (EpsDeleter) session.getAttribute("EpsChart_Deleter"); if (chartDeleter == null) { chartDeleter = new EpsDeleter(); session.setAttribute("EpsChart_Deleter", chartDeleter); }/*from www . j a va 2 s . co m*/ chartDeleter.addChart(tempFile.getName()); System.out.println("add a chart to delete: " + tempFile.getName()); } else { System.out.println("Session is null - chart will not be deleted"); } }
From source file:com.jdon.strutsutil.FormBeanUtil.java
/** * lookup ActionForm in/*from ww w. j a v a2 s . co m*/ * * @param request * @return */ public static ActionForm lookupActionForm(HttpServletRequest request, String formName) { ActionForm actionForm = null; actionForm = (ActionForm) request.getAttribute(formName); if (actionForm == null && request.getSession(false) != null) { HttpSession session = request.getSession(false); actionForm = (ActionForm) session.getAttribute(formName); } return actionForm; }
From source file:com.vangent.hieos.DocViewer.server.framework.ServletUtilMixin.java
/** * /* w w w . j av a 2 s .c om*/ * @param request * @return */ static public boolean isValidSession(HttpServletRequest request) { boolean validSession = false; // Get session. HttpSession session = request.getSession(false); if (session != null) { // See if we have a valid session. String loginSuccess = (String) session.getAttribute(SESSION_PROPERTY_AUTH_STATUS); if (loginSuccess == null || !loginSuccess.equals("true")) { // Do not continue. validSession = false; } else { // Continue. validSession = true; } } return validSession; }
From source file:com.webapp.desc.WebApp.java
/** * Retrieve a login from the current request. * /*ww w.j a v a 2 s . c om*/ * @param request The HTTP request containing container session and cookie data * * @return the login associated with the request, or null if the user has not logged into the system with valid credentials. */ public static Login getLogin(HttpServletRequest request) { Login retval = null; HttpSession session = request.getSession(true); try { retval = (Login) session.getAttribute(SESSION_LOGIN_KEY); } catch (Exception e) { LOG.error(e); } // If the login was not in the HTTP session, check for the cookie if (retval == null) { if (request != null) { String sessionid = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (COOKIE_SESSION_KEY.equals(cookies[i].getName())) { sessionid = cookies[i].getValue(); break; } } if (StringUtil.isNotBlank(sessionid)) { if (securityContext != null) { LOG.trace("Retrieving security session for " + sessionid); Session msession = securityContext.getSession(sessionid); if (msession != null) { // TODO: It might be interesting to ensure that // the servlet session identifier matches data // stored in the security context's session as // an additional check retval = msession.getLogin(); LOG.trace("Using existing session from security context"); } else { LOG.warn("No security session for session ID :" + sessionid); // TODO: Should we clear the cookie since we // lost the session? } } else { LOG.warn("Security Context not set"); } } // session id !null } // cookies !null } // request !null } // login was not stored in the local http session // return what we retrieved return retval; }
From source file:com.alibaba.citrus.turbine.util.CsrfToken.java
public static LinkedList<String> getTokensInSession(HttpSession session, String tokenKey) { return createLinkedList(StringUtil.split((String) session.getAttribute(tokenKey), CSRF_TOKEN_SEPARATOR)); }
From source file:gov.nih.nci.cabig.ctms.web.WebTools.java
@SuppressWarnings({ "unchecked" }) public static SortedMap<String, Object> sessionAttributesToMap(final HttpSession session) { if (session != null) { return namedAttributesToMap(session.getAttributeNames(), new AttributeAccessor() { public Object getAttribute(String name) { return session.getAttribute(name); }/*from ww w. j av a2 s.c o m*/ }); } else { return emptySortedMap(); } }
From source file:in.mycp.utils.Commons.java
public static String getSessionMsg() { try {//from w ww .j av a 2s .co m HttpSession session = WebContextFactory.get().getSession(); return (String) session.getAttribute("session_msg"); } catch (Exception e) { log.error(e.getMessage()); } return ""; }
From source file:com.ecyrd.jspwiki.preferences.Preferences.java
/** * This is an utility method which is called to make sure that the * JSP pages do have proper access to any user preferences. It should be * called from the commonheader.jsp.//from w ww .ja v a2 s . co m * <p> * This method reads user cookie preferences and mixes them up with any * default preferences (and in the future, any user-specific preferences) * and puts them all in the session, so that they do not have to be rewritten * again. * <p> * This method will remember if the user has already changed his prefs. * * @param pageContext The JSP PageContext. */ public static void setupPreferences(PageContext pageContext) { HttpSession session = pageContext.getSession(); if (session.getAttribute(SESSIONPREFS) == null) { reloadPreferences(pageContext); } }