List of usage examples for javax.servlet.http HttpServletRequest getSession
public HttpSession getSession(boolean create);
From source file:com.vangent.hieos.DocViewer.server.framework.ServletUtilMixin.java
/** * /*from ww w. ja v a 2s . 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:edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.java
/** * Get the bean from the session, or null if there is no bean. */// w w w. j av a2 s.c om private static LoginProcessBean getBeanFromSession(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session == null) { return null; } Object bean = session.getAttribute(SESSION_ATTRIBUTE); if (bean == null) { return null; } if (!(bean instanceof LoginProcessBean)) { log.warn("Tried to get login process bean, but found an instance of " + bean.getClass().getName() + ": " + bean); return null; } return (LoginProcessBean) bean; }
From source file:de.anycook.session.Session.java
static public Session init(HttpServletRequest request) { Session session = init(request.getSession(true)); if (session.login == null) { try {//from www.j ava 2 s . c om session.loginWithCookies(request.getCookies()); } catch (IOException | SQLException e) { LogManager.getLogger(Session.class).error(e, e); } } return session; }
From source file:com.swdouglass.joid.server.OpenIdServlet.java
/** * * @param request//from ww w. ja va 2 s . c o m * @param username if null, will logout */ public static void setLoggedIn(HttpServletRequest request, String username) { request.getSession(true).setAttribute(USERNAME_ATTRIBUTE, username); }
From source file:gov.nih.nci.cabig.caaers.web.ae.AdverseEventReconciliationController.java
public static void clearCommandObject(HttpServletRequest request) { request.getSession(true).removeAttribute(commandName); }
From source file:com.webapp.desc.WebApp.java
/** * Retrieve a login from the current request. * /*from w w w . ja v a2 s. c o m*/ * @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:org.craftercms.core.util.HttpServletUtils.java
public static Map<String, Object> createSessionMap(HttpServletRequest request) { Map<String, Object> sessionMap = new HashMap<String, Object>(); HttpSession session = request.getSession(false); if (session != null) { for (Enumeration attributeNameEnum = session.getAttributeNames(); attributeNameEnum .hasMoreElements();) {/*from w ww . j a v a 2 s .com*/ String attributeName = (String) attributeNameEnum.nextElement(); sessionMap.put(attributeName, session.getAttribute(attributeName)); } } return sessionMap; }
From source file:com.swdouglass.joid.server.OpenIdServlet.java
/** * * @param request//from w w w .j a v a2 s.co m * @return Username the user is logged in as */ public static String getLoggedIn(HttpServletRequest request) { String o = (String) request.getSession(true).getAttribute(USERNAME_ATTRIBUTE); if (o != null) { return o; } // check Remember Me cookies String authKey = CookieUtils.getCookieValue(request, COOKIE_AUTH_NAME, null); if (authKey != null) { String username = CookieUtils.getCookieValue(request, COOKIE_USERNAME, null); if (username != null) { // lets check the UserManager to make sure this is a valid match o = getUserManager().getRememberedUser(username, authKey); if (o != null) { request.getSession(true).setAttribute(USERNAME_ATTRIBUTE, o); } } } return o; }
From source file:org.artifactory.webapp.servlet.RequestUtils.java
public static void removeAuthentication(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(LAST_USER_KEY); }/*from www.jav a 2 s.c om*/ }
From source file:org.artifactory.webapp.servlet.RequestUtils.java
public static Authentication getAuthentication(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session == null) { return null; }// w w w . ja va 2 s . co m return (Authentication) session.getAttribute(LAST_USER_KEY); }