Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession(boolean create);

Source Link

Document

Returns the current <code>HttpSession</code> associated with this request or, if there is no current session and <code>create</code> is true, returns a new session.

Usage

From source file:org.appverse.web.framework.backend.api.helpers.security.SessionAttributePreAuthenticatedProcessingFilter.java

@Override
protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
    HttpSession httpSession = request.getSession(false);
    if (httpSession == null) {
        throw new PreAuthenticatedCredentialsNotFoundException(
                principalSessionAttribute + " attribute not found in session.");
    }//from   ww  w. j a  va2s  . c o  m
    String principal = (String) httpSession.getAttribute(principalSessionAttribute);
    if (principal == null) {
        throw new PreAuthenticatedCredentialsNotFoundException(
                principalSessionAttribute + " attribute not found in session.");
    }
    return principal;
}

From source file:org.soundstage.web.controller.LoginUserController.java

@RequestMapping(method = RequestMethod.POST, value = "/Login.do")
public String login(HttpServletRequest request, Model model) {
    System.out.println(request.getSession(false).getId());
    return "LoginUser";
}

From source file:org.soundstage.web.controller.LoginUserController.java

@RequestMapping("/GuestUser.view")
public String GuestUser(HttpServletRequest request, Model model) {
    System.out.println(request.getSession(false).getId());
    return "GuestUser";
}

From source file:org.soundstage.web.controller.LoginUserController.java

@RequestMapping(value = "/AboutUs.view")
public String AboutUs(HttpServletRequest request, Model model) {
    System.out.println(request.getSession(false).getId());
    return "AboutUs";
}

From source file:org.soundstage.web.controller.LoginUserController.java

@RequestMapping({ "/FrontApp.view", "/Home.view" })
public String frontApp(HttpServletRequest request, Model model) {
    HttpSession session = request.getSession(true);
    System.out.println(session.getId());
    return "header";
}

From source file:org.sventon.appl.ConfigAuthorizationFilter.java

/**
 * Checks if the user is already logged in to the config pages.
 *
 * @param request Request.//from  w w  w  .  j a va 2 s.  c  om
 * @return True if the attribute {@code isAdminLoggedIn} is set on the HTTP session.
 */
private boolean isAlreadyLoggedIn(final HttpServletRequest request) {
    return request.getSession(true).getAttribute("isAdminLoggedIn") != null;
}

From source file:ste.web.beanshell.jetty.BeanShellUtils.java

public static void setup(final Interpreter interpreter, final HttpServletRequest request,
        final HttpServletResponse response) throws EvalError, IOException {
    ///*  ww  w. ja  v  a2  s. c  o m*/
    // Set attributes as script variables
    //
    String k, key;
    for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
        k = (String) e.nextElement();
        key = normalizeVariableName(k);
        interpreter.set(key, request.getAttribute(k));
    }

    //
    // Set request parameters as script variables. Note that parameters
    // override attributes
    //
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
        k = (String) e.nextElement();
        key = normalizeVariableName(k);
        interpreter.set(key, request.getParameter(k));
    }

    interpreter.set(VAR_REQUEST, request);
    interpreter.set(VAR_RESPONSE, response);
    interpreter.set(VAR_SESSION, request.getSession(false));
    interpreter.set(VAR_OUT, response.getWriter());
    interpreter.set(VAR_LOG, log);
    if (hasJSONBody(request)) {
        interpreter.set(VAR_BODY, getJSONBody(request.getInputStream()));
    }
}

From source file:com.tunisbank.service.UsersControllers.java

@RequestMapping("/users/logout")
public ModelAndView logout(HttpServletRequest request) {
    request.getSession(true).removeAttribute("user");
    Map model = new HashMap();
    model.put("anim", "blind");
    tryLogin = false;//from w w w  .jav a2 s .  c o m
    System.out.println("ok");
    return new ModelAndView(new RedirectView("/users/login.html", true), model);
}

From source file:org.bpmscript.web.LogoutController.java

/**
 * Invalidate the session and redirect the browser to contextPath/index.html
 *///w w  w.  j  a  va 2s. com
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    request.getSession(true).invalidate();
    return new ModelAndView(new RedirectView(request.getContextPath() + "/index.html"));
}

From source file:org.itracker.web.util.LoginUtilities.java

public static User setupSession(User user, String encPassword, HttpServletRequest request,
        HttpServletResponse response) {//from  ww w.j av  a 2s. co m
    if (user == null) {
        logger.warn("setupSession: null user", (logger.isDebugEnabled() ? new RuntimeException() : null));
        throw new IllegalArgumentException("null user");
    }

    UserService userService = ServletContextUtils.getItrackerServices().getUserService();

    if (logger.isDebugEnabled()) {
        logger.debug("Creating new session");
    }
    HttpSession session = request.getSession(true);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting session timeout to " + getConfiguredSessionTimeout() + " minutes");
    }
    session.setMaxInactiveInterval(getConfiguredSessionTimeout() * 60);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting session tracker");
    }
    session.setAttribute(Constants.SESSION_TRACKER_KEY, new SessionTracker(user.getLogin(), session.getId()));

    if (logger.isDebugEnabled()) {
        logger.debug("Setting user information");
    }
    session.setAttribute(Constants.USER_KEY, user);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting preferences for user " + user.getLogin());
    }
    UserPreferences userPrefs = user.getPreferences();
    // TODO : this is a hack, remove when possible
    if (userPrefs == null) {
        logger.warn("setupSession: got user with no preferences!: " + user + " (prefs: " + user.getPreferences()
                + ")");
        userPrefs = new UserPreferences();
    }
    session.setAttribute(Constants.PREFERENCES_KEY, userPrefs);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting user " + user + " locale to "
                + ITrackerResources.getLocale(userPrefs.getUserLocale()));
    }
    session.setAttribute(Constants.LOCALE_KEY, ITrackerResources.getLocale(userPrefs.getUserLocale()));

    // TODO: cookie could be removed
    Cookie cookie = new Cookie(Constants.COOKIE_NAME, "");
    cookie.setPath(request.getContextPath());

    cookie.setValue("");
    cookie.setMaxAge(0);

    response.addCookie(cookie);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting permissions for user " + user.getLogin());
    }
    Map<Integer, Set<PermissionType>> usersMapOfProjectIdsAndSetOfPermissionTypes = userService
            .getUsersMapOfProjectIdsAndSetOfPermissionTypes(user, AuthenticationConstants.REQ_SOURCE_WEB);
    session.setAttribute(Constants.PERMISSIONS_KEY, usersMapOfProjectIdsAndSetOfPermissionTypes);

    // Reset some session forms
    session.setAttribute(Constants.SEARCH_QUERY_KEY, null);

    SessionManager.clearSessionNeedsReset(user.getLogin());
    if (logger.isDebugEnabled()) {
        logger.debug("User session data updated.");
    }
    return user;
}