Example usage for javax.servlet.http HttpSession removeAttribute

List of usage examples for javax.servlet.http HttpSession removeAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession removeAttribute.

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes the object bound with the specified name from this session.

Usage

From source file:com.lm.lic.manager.util.GenUtil.java

public static void removeProductUnderManagement(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    session.removeAttribute("prodId");
}

From source file:edu.cornell.mannlib.vitro.webapp.filestorage.TempFileHolder.java

/**
 * Get the {@link TempFileHolder} which is stored as an attribute on this
 * session, extract the {@link FileInfo} from it, and remove it from the
 * session.//from   ww w .  j a v a 2  s. co  m
 * 
 * If there is no such attribute, of if it is not a {@link TempFileHolder},
 * return null.
 */
public static FileInfo remove(HttpSession session, String attributeName) {
    if (session == null) {
        throw new NullPointerException("session may not be null.");
    }
    if (attributeName == null) {
        throw new NullPointerException("attributeName may not be null.");
    }
    Object attribute = session.getAttribute(attributeName);
    if (attribute instanceof TempFileHolder) {
        FileInfo fileInfo = ((TempFileHolder) attribute).extractFileInfo();
        session.removeAttribute(attributeName);
        log.debug("remove this file: " + fileInfo);
        return fileInfo;
    } else if (attribute == null) {
        return null;
    } else {
        session.removeAttribute(attributeName);
        return null;
    }
}

From source file:com.lm.lic.manager.util.GenUtil.java

/**
 * @param session//  ww w .  j av  a2s  .  c o  m
 */
public static void invalidateSession(HttpSession session) {
    if (session != null) {
        session.removeAttribute(GenUtil.LOGGED_IN_ATTRIBUTE);
        session.invalidate();
    }
}

From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java

/**
* Tries to destroy the current session and reclaim associated resources
*
* @param requestWrapper/*  w  w w .j a  v  a 2  s .co  m*/
* @return true, if the session was destroyed. false, if there was none.
*/
@SuppressWarnings({ "unchecked" })
private static boolean didDestroySessionOnRequest(@NotNull HttpServletRequest requestWrapper) {
    if ("destroy".equalsIgnoreCase(requestWrapper.getParameter("m"))) {
        final HttpSession session = getSessionOrFail(requestWrapper);
        if (session != null) {
            synchronized (session) {
                final Enumeration<String> attrs = (Enumeration<String>) session.getAttributeNames();
                while (attrs.hasMoreElements())
                    session.removeAttribute(attrs.nextElement());
                session.invalidate();
            }
        }
        return true;
    } else
        return false;
}

From source file:com.lm.lic.manager.util.GenUtil.java

/**
 * @param session//ww w  .ja  va2 s . c  o m
 */
public static void invalidateSession(LoginService loginService, HttpSession session) {
    if (session != null) {
        User user = (User) session.getAttribute("user");
        if (user != null)
            loginService.makeUserLoggedOut(user, session);
        session.removeAttribute(GenUtil.LOGGED_IN_ATTRIBUTE);
        session.invalidate();
    }
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Set the session attribute with the given name to the given value.
 * Removes the session attribute if value is null, if a session existed at all.
 * Does not create a new session if not necessary!
 * @param request current HTTP request//from w w w .ja v  a  2  s.  co m
 * @param name the name of the session attribute
 * @param value the value of the session attribute
 */
public static void setSessionAttribute(HttpServletRequest request, String name, Object value) {
    Assert.notNull(request, "Request must not be null");
    if (value != null) {
        request.getSession().setAttribute(name, value);
    } else {
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.removeAttribute(name);
        }
    }
}

From source file:edu.stanford.muse.webapp.Sessions.java

private static void removeAllAttributes(HttpSession session) {
    java.util.Enumeration keys = session.getAttributeNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        if ("cacheDir".equals(key) || "userKey".equals(key) || "museEmailFetcher".equals(key))
            // do not remove "cacheDir"/"userKey" which may be user-provided.
            // do not remove "museEmailFetcher" which is required for fetching.
            // TODO: this is getting ugly. maybe we should do the opposite = removing only certain attributes.
            continue;
        session.removeAttribute(key);
    }//from www  . jav  a2s .c  om
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration.java

public static void clearAllConfigsInSession(HttpSession sess) {
    if (sess == null)
        return;//from w ww .j a  v  a 2  s . c  om
    sess.removeAttribute("editConfiguration");
}

From source file:net.groupbuy.controller.shop.LogoutController.java

/**
 * /*from w w w. j  a  v  a 2s.  c o  m*/
 */
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String execute(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
    session.removeAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME);
    WebUtils.removeCookie(request, response, Member.USERNAME_COOKIE_NAME);
    return "redirect:/";
}

From source file:eionet.util.SecurityUtil.java

/**
 * Returns current user, or null, if the current session does not have user attached to it.
 *///  w  w w .ja v  a 2s  .  c  o  m
public static final DDUser getUser(HttpServletRequest request) {

    HttpSession session = request.getSession();
    DDUser user = session == null ? null : (DDUser) session.getAttribute(REMOTEUSER);

    if (user == null) {
        String casUserName = session == null ? null : (String) session.getAttribute(CASFilter.CAS_FILTER_USER);
        if (casUserName != null) {
            user = DDCASUser.create(casUserName);
            session.setAttribute(REMOTEUSER, user);
        }
    } else if (user instanceof DDCASUser) {
        String casUserName = (String) session.getAttribute(CASFilter.CAS_FILTER_USER);
        if (casUserName == null) {
            user.invalidate();
            user = null;
            session.removeAttribute(REMOTEUSER);
        } else if (!casUserName.equals(user.getUserName())) {
            user.invalidate();
            user = DDCASUser.create(casUserName);
            session.setAttribute(REMOTEUSER, user);
        }
    }

    if (user != null) {
        return user.isAuthentic() ? user : null;
    } else {
        return null;
    }
}