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.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/logout", method = RequestMethod.GET)
@Timed//w w  w  .  ja v a  2 s . c o m
@ExceptionMetered
public ModelMap logout(HttpSession session) {
    session.removeAttribute("email");
    return new ModelMap("result", "ok");
}

From source file:de.micromata.genome.gwiki.auth.GWikiSessionAttributesUserAuthentification.java

protected GWikiSimpleUser initUserFromSession(GWikiContext ctx) {
    HttpSession session = ctx.getSession(false);
    if (session == null) {
        return null;
    }//from  ww  w .  j  av a 2s .  co m
    Object oumap = session.getAttribute(GWIKI_SESSION_ATTRIBUTE);
    if ((oumap instanceof Map) == false) {
        session.removeAttribute(GWIKI_SESSION_ATTRIBUTE);
        return null;
    }
    Map<String, Object> umap = (Map<String, Object>) oumap;
    GWikiSimpleUser nsu = new GWikiSimpleUser();
    nsu.setUser((String) umap.get("userName"));
    nsu.setEmail((String) umap.get("email"));
    nsu.setRightsMatcherRule((String) umap.get("rightsMatcherRule"));
    Object oprops = umap.get("props");
    if (oprops instanceof Map) {
        nsu.setProps((Map<String, String>) oprops);
    }
    GWikiUserServeElementFilterEvent.setUser(nsu);
    return nsu;
}

From source file:com.androgogic.AikauPageView.java

@Override
protected String buildLoginRedirectURL(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session != null && session.getAttribute(REDIRECT_URI) != null) {
        String redirectUrl = session.getAttribute(REDIRECT_URI)
                + (session.getAttribute(REDIRECT_QUERY) != null ? ("?" + session.getAttribute(REDIRECT_QUERY))
                        : "");
        session.removeAttribute(REDIRECT_URI);
        session.removeAttribute(REDIRECT_QUERY);
        return redirectUrl;
    }//  w  ww. j a va  2 s.  c o m
    return super.buildLoginRedirectURL(request);
}

From source file:com.curl.orb.servlet.DestroyInstanceServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    super.doPost(request, response);
    Log log = LogFactory.getLog(getClass());
    DestroyInstanceRequest destroyInstanceRequest = (DestroyInstanceRequest) InstanceManagementUtil
            .getRequest(request);/*from  www. jav a 2  s. co  m*/
    try {
        HttpSession session = request.getSession(false);
        if (session == null)
            throw new InstanceManagementException("Does not exist HttpSession.");
        String objectId = destroyInstanceRequest.getObjectId();
        Object obj = session.getAttribute(objectId);
        // security
        RemoteServiceAnnotationChecker.check(obj.getClass(), environment);
        // remove the object from session
        session.removeAttribute(objectId);

        // kill session
        if (destroyInstanceRequest.getHeader() != null
                && destroyInstanceRequest.getHeader().containsKey(KILL_SESSION)
                && (Boolean) destroyInstanceRequest.getHeader().get(KILL_SESSION)) {
            log.debug("Killed HttpSession:" + session.getId());
            session.invalidate();
        }
        InstanceManagementUtil.setResponse(request, null, null);
        log.debug("Request destroyed");
    }
    // IOException, SerializerException, InstanceManagementException
    catch (Exception e) {
        InstanceManagementUtil.setResponse(request, e, null);
    }
}

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

public synchronized void sessionWillPassivate(HttpSessionEvent event) {
    final HttpSession evSession = event.getSession();
    if (evSession != null) {
        evSession.removeAttribute(getToken());
    }//from   w  w  w  .  ja  v  a2  s . co  m
}

From source file:id.ac.ipb.ilkom.training.controller.OrderController.java

@RequestMapping(value = "/checkout", method = RequestMethod.GET)
public String checkout(Model model, HttpSession session) {
    Customer customer = (Customer) session.getAttribute("customer");
    if (customer == null) {
        return "redirect:/";
    }/*w  ww. j  a  va 2s.  c  o m*/
    Order order = (Order) session.getAttribute("cart");
    if (order == null) {
        return "redirect:/";
    }
    orderService.save(order);
    model.addAttribute("checkout", order);
    session.setAttribute("cart", null);
    session.removeAttribute("cart");

    return "checkout";
}

From source file:com.mirth.connect.server.servlets.UserServlet.java

private void logout(HttpServletRequest request, UserController userController, EventController eventController)
        throws ServletException {
    HttpSession session = request.getSession();

    // save the session id before removing them from the session
    Integer userId = (Integer) session.getAttribute(SESSION_USER);
    String sessionId = session.getId();

    // remove the sessions attributes
    session.removeAttribute(SESSION_USER);
    session.removeAttribute(SESSION_AUTHORIZED);

    // invalidate the current sessions
    session.invalidate();/*  w  ww . j a va  2s.  c  o m*/

    // set the user status to logged out in the database
    User user = new User();
    user.setId(userId);

    try {
        userController.logoutUser(user);
    } catch (ControllerException ce) {
        throw new ServletException(ce);
    }

    // delete any temp tables created for this session
    ControllerFactory.getFactory().createMessageObjectController().removeFilterTable(sessionId);
    eventController.removeFilterTable(sessionId);
}

From source file:fr.paris.lutece.portal.service.admin.AdminAuthenticationService.java

/**
 * Returns the url (asked before login) to redirect after login
 * @param request The Http request//from w  w  w .ja  v a2s . c  om
 * @return The url asked before login
 */
public String getLoginNextUrl(HttpServletRequest request) {
    String strNextUrl = StringUtils.EMPTY;
    HttpSession session = request.getSession(false);

    if (session != null) {
        strNextUrl = (String) session.getAttribute(ATTRIBUTE_ADMIN_LOGIN_NEXT_URL);
        session.removeAttribute(ATTRIBUTE_ADMIN_LOGIN_NEXT_URL);
    }

    return strNextUrl;
}

From source file:com.mirth.connect.server.api.servlets.UserServlet.java

@Override
@DontCheckAuthorized/*from ww  w  . ja v  a  2s.  com*/
public void logout() {
    // Audit the logout request but don't block it
    isUserAuthorized();

    HttpSession session = request.getSession();

    // save the session id before removing them from the session
    Integer userId = (Integer) session.getAttribute(SESSION_USER);

    // remove the sessions attributes
    session.removeAttribute(SESSION_USER);
    session.removeAttribute(SESSION_AUTHORIZED);

    // invalidate the current sessions
    session.invalidate();

    // set the user status to logged out in the database
    User user = new User();
    user.setId(userId);

    try {
        userController.logoutUser(user);
    } catch (ControllerException e) {
        throw new MirthApiException(e);
    }
}

From source file:com.megacasting_ppe.web.ServletPageError.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w w .ja v a 2 s .c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json");
    response.setHeader("Cache-Control", "no-cache");
    HttpSession session = request.getSession();

    JSONObject global = new JSONObject();

    if (session.getAttribute("Connecter") != null) {
        String connecterCandidatOk = (String) session.getAttribute("Connecter");
        if (connecterCandidatOk == "false") {

            global.put("candidatAutherreur",
                    "le nom d'utilisateur ou le mot de passe du candidat est incorrect");
            session.removeAttribute("Connecter");
        }
    }
    if (session.getAttribute("ConnecterDiffuseur") != null) {
        String connecterDiffuseurOk = (String) session.getAttribute("ConnecterDiffuseur");
        if (connecterDiffuseurOk == "false") {

            global.put("diffuseurAutherreur",
                    "le nom d'utilisateur ou le mot de passe du diffuseur est incorrect");
            session.removeAttribute("ConnecterDiffuseur");
        }
    }

    if (session.getAttribute("ErreurInscriptionCandidat") != null) {
        String ErreurInscription = (String) session.getAttribute("ErreurInscriptionCandidat");
        if (ErreurInscription == "true") {

            global.put("Inscriptionerreur",
                    "Un ou plusieurs champs saisies dans le formulaire d'inscription sont invalide");
            session.removeAttribute("ErreurInscriptionCandidat");
        }
    }

    try (PrintWriter out = response.getWriter()) {
        out.println(global.toString());
    }

}