Example usage for javax.servlet.http HttpSession setAttribute

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

Introduction

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

Prototype

public void setAttribute(String name, Object value);

Source Link

Document

Binds an object to this session, using the name specified.

Usage

From source file:edu.vt.middleware.ldap.servlets.session.DefaultSessionManager.java

/**
 * This performs any actions necessary to login the suppled user.
 *
 * @param  session  <code>HttpSession</code>
 * @param  user  <code>String</code>
 *
 * @throws  ServletException  if an error occurs initializing the session
 *//*from ww w .j  av  a 2  s . c  om*/
public void login(final HttpSession session, final String user) throws ServletException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Begin login method");
    }
    if (this.sessionId != null) {
        session.setAttribute(this.sessionId, user);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Set session attribute " + this.sessionId + " to " + user);
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Could not set session attribute, value is null");
        }
    }
}

From source file:cn.vlabs.umt.ui.servlet.LoginServlet.java

private void saveParams(HttpServletRequest request) {
    int port = request.getServerPort();
    HttpSession session = request.getSession();
    String basePath = request.getScheme() + "://" + request.getServerName();
    if (port != 80) {
        basePath += ":" + request.getServerPort();
    }// ww  w  .  j  a  va2s .c  o m
    session.setAttribute("rootPath", basePath);
    basePath += request.getContextPath();
    session.setAttribute("basePath", basePath);
    Map<String, String> siteInfo = new HashMap<String, String>();
    for (String param : Attributes.SSO_PARAMS) {
        if (request.getParameter(param) != null) {
            siteInfo.put(param, request.getParameter(param));
        }
    }
    session.setAttribute(Attributes.SITE_INFO, siteInfo);
}

From source file:com.music.web.AuthenticationController.java

@RequestMapping(value = "/signin/{providerId}", method = RequestMethod.GET, params = "home") //param to discriminate from the cancellation url (ugly, I know)
public RedirectView signin(@PathVariable String providerId, @RequestParam(required = false) String redirectUri,
        NativeWebRequest request, HttpSession session) {
    if (redirectUri != null) {
        session.setAttribute(REDIRECT_AFTER_LOGIN, redirectUri);
    }//from  w  w w  .  jav a 2 s .  c  o m
    return signInController.signIn(providerId, request);
}

From source file:be.fedict.eid.dss.webapp.ProtocolEntryServlet.java

private void storeProtocolServiceContextPath(String contextPath, HttpSession httpSession) {
    httpSession.setAttribute(PROTOCOL_SERVICE_CONTEXT_PATH_SESSION_ATTRIBUTE, contextPath);
}

From source file:puma.sp.authentication.controllers.authentication.AccessController.java

private String ensureRelayState(HttpSession session) {
    String result = (String) session.getAttribute("RelayState");
    if (result == null || result.isEmpty()) {
        result = DEFAULT_RELAYSTATE;//from  w  w w . j a  v a 2s  . c o m
        session.setAttribute("RelayState", result);
    }
    return result;
}

From source file:whitelabel.cloud.webapp.impl.controller.AccessController.java

@RequestMapping(value = { "/login_ok", "/login_ok/" })
public String loginOk(HttpServletRequest request, HttpServletResponse response, Model model) {

    HttpSession session = request.getSession(true);
    String home = "home";
    if (session != null) {

        CloudUser user = UserUtil.getUser();

        synchronized (session) {
            session.setAttribute(CloudUser.SESSION_NAME, user);
        }//from ww w .j  a v  a 2s.co  m

    }
    return "redirect:" + home;
}

From source file:progetto.informatica.ControllerRegistrati.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestParam(value = "nick") String nick,
        @RequestParam(value = "password") String password, HttpSession session) {
    Utente u = crud.selectUtente(nick);//from   w  w  w. ja v  a2 s  .  co m
    if (u != null) {
        try {
            String hash = Password.getMD5(password);
            if (u.getPassword().equals(hash)) {
                session.setAttribute("nick", nick);
                session.setAttribute("password", password);
                return "index";
            }
            return "login";
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(ControllerRegistrati.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return "login";
}

From source file:ua.aits.crc.controller.SystemController.java

@RequestMapping(value = { "/system/do/login", "/system/do/login/" }, method = RequestMethod.POST)
public ModelAndView login(@RequestParam("user_name") String user_name,
        @RequestParam("user_password") String user_password, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    request.setCharacterEncoding("UTF-8");
    HttpSession session = request.getSession(true);
    session.setAttribute("user", "admin");
    return new ModelAndView("redirect:" + "/system/index");
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.actions.SaveExpLoginAction.java

/**
 * Process the specified HTTP request, and create the corresponding HTTP
 * response (or forward to another web component that will create it).
 * Return an <code>ActionForward</code> instance describing where and how
 * control should be forwarded, or <code>null</code> if the response has
 * already been completed./*from  w  w  w .j a  va  2 s .  c om*/
 *
 * @param mapping The ActionMapping used to select this instance
 * @param actionForm The optional ActionForm bean for this request (if any)
 * @param request The HTTP request we are processing
 * @param response The HTTP response we are creating
 *
 * @exception Exception if the application business logic throws
 *  an exception
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Extract attributes we will need
    HttpSession session = request.getSession();

    if ("request".equals(mapping.getScope())) {
        request.setAttribute(mapping.getAttribute(), form);
    } else {
        session.setAttribute(mapping.getAttribute(), form);
    }

    DynaValidatorForm loginForm = (DynaValidatorForm) form;

    String email = (String) loginForm.get("email");
    String password = (String) loginForm.get("password");

    int expId = ControlServ.dbw.getClientIdByEmailAndPassword(email, password, JMConstants.EXPERIMENTER_ROLE);

    if (expId < 0) {
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.exp.notRegistered"));
        saveErrors(request, errors);
        return (mapping.findForward("failure"));
    }

    loginExperimenter(session, expId);

    return (mapping.findForward("success"));
}

From source file:controller.PostsController.java

@RequestMapping(value = "home", method = RequestMethod.GET)
public ModelAndView handleHome(HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (session == null || !request.isRequestedSessionIdValid()) {
        return new ModelAndView("index");
    }/*from   w  w w . j  ava  2 s .com*/

    session.setAttribute("currentPage", "/home.htm");

    // Get all the posts sent to this user
    UsersEntity user = (UsersEntity) session.getAttribute("user");
    ArrayList<PostsEntity> posts = this.postsService.searchByTarget(user);

    // Add the posts sent by this user
    for (PostsEntity post : this.postsService.searchBySender(user)) {
        if (!posts.contains(post)) {
            posts.add(post);
        }
    }

    // Add the posts sent by friends
    for (UsersEntity friend : user.getFriends()) {
        for (PostsEntity post : this.postsService.searchBySender(friend)) {
            if (!posts.contains(post)) {
                posts.add(post);
            }
        }
    }

    Collections.sort(posts, Collections.reverseOrder());

    ModelAndView mv = new ModelAndView("home");
    mv.addObject("currentUser", user);
    mv.addObject("posts", posts);
    mv.addObject("nbNotifs", this.notifsService.searchByTarget(user).size());

    return mv;
}