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:org.openmrs.module.clinicalsummary.web.controller.summary.MappingFormController.java

@RequestMapping(method = RequestMethod.POST)
public String processPage(final @ModelAttribute("mapping") Mapping mapping, final HttpSession session) {
    Context.getService(SummaryService.class).saveMapping(mapping);
    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "clinicalsummary.mapping.saved");
    return "redirect:mappingList.list";
}

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

@RequestMapping(value = "/ServiceAccessServlet", method = RequestMethod.GET)
public String accessService(@RequestParam(value = "RelayState", defaultValue = "") String relayState,
        @RequestParam(value = "Tenant", defaultValue = "") String tenantIdentifier,
        @RequestParam(value = "Post", defaultValue = "false") Boolean post, ModelMap model,
        HttpSession session) {
    session.setAttribute("Post", post);
    if (session.getAttribute("Authenticated") == null
            || !((Boolean) session.getAttribute("Authenticated")).booleanValue()) {
        session.removeAttribute("Tenant");
        // Ensure relay state is in place
        session.setAttribute("RelayState", relayState);
        this.ensureRelayState(session);
        // Tenant Identifier
        Tenant tenantObject = null;//  w  w w.j a  v  a 2 s  .c o m
        if (tenantIdentifier == null || tenantIdentifier.isEmpty()) {
            session.setAttribute("FlowRedirectionElement", new FlowDirecter("/SubmitWAYF"));
            return "redirect:/";
        } else {
            tenantObject = this.tenantService.findOne(Long.parseLong(tenantIdentifier));
            if (tenantObject == null) {
                logger.log(Level.WARNING, "Could not find tenant with identifier " + tenantIdentifier);
                MessageManager.getInstance().addMessage(session, "info",
                        "Could not find any tenant with identifier " + tenantIdentifier);
                session.setAttribute("FlowRedirectionElement", new FlowDirecter("/SubmitWAYF"));
                return "redirect:/";
            }
        }
        session.setAttribute("Tenant", tenantObject);
        // Redirect to next flow element
        return "redirect:/AuthenticationRequestServlet";
    } else {
        // Subject is already authenticated
        if (relayState != null && !relayState.isEmpty())
            session.setAttribute("RelayState", relayState);
        return "redirect:/AuthenticationResponseServlet";
    }
}

From source file:info.toegepaste.www.controller.LoginController.java

public String DoLogin() {
    docent = getDocent(login, pass);//from   w  w  w . ja  v a  2s  .c o  m
    if (docent != null) {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
        session.setAttribute("docent", docent);

        return "home";
    } else {
        error = "Your username or password is not valid!";
        return "index";
    }
}

From source file:com.zq.fin.seckill.web.BaseController.java

 /**
 * ?//from w  w  w.  ja  v a2 s.c o m
 * ??
 * ??
 */
protected void setRedirectUrlToHttpServletRequest(String redirectUrl, HttpServletRequest request){
   HttpSession httpSession = request.getSession();
      
   httpSession.setAttribute(REDIRECT_URL, redirectUrl);
}

From source file:nl.surfnet.coin.selfservice.control.identity.IdentityController.java

private void newIdentity(IdentitySwitch identitySwitch, HttpServletRequest request,
        InstitutionIdentityProvider provider) {
    HttpSession session = request.getSession();
    session.setAttribute(SELECTED_IDP, provider);
    session.setAttribute(SWITCHED_IDENTITY_SWITCH, identitySwitch);
    session.setAttribute(NOTIFICATIONS, null);
    session.setAttribute(NOTIFICATION_POPUP_CLOSED, null);
}

From source file:com.fpmislata.banco.presentation.controladores.LoginController.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public void read(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    try {/*from   w  ww .  jav a 2 s .c  o  m*/
        Usuario usuario = new Usuario("Daniel", passwordManager.encrypt("12345"));
        HttpSession httpSession = httpServletRequest.getSession();
        WebSession webSession = new WebSession(usuario, new Date());
        httpSession.setAttribute("webSession", webSession);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.starr.smartbuilds.controller.AuthController.java

@RequestMapping(method = { RequestMethod.POST })
public String addUser(@ModelAttribute("auth") AuthService auth, Model model, HttpServletRequest req,
        HttpServletResponse resp) throws IOException {
    User user = auth.checkAuth(userDAO);
    HttpSession session = req.getSession();
    if (user != null) { // 
        session.setAttribute("user", user);
        resp.sendRedirect("./");
    } else {/* w ww .j a  va2 s  . co m*/
        model.addAttribute("authMsg", "<a href='./auth'>Log in</a>");
        model.addAttribute("exitReg", "<a href='./reg'>Register</a>");
        model.addAttribute("result", "<font color='red'><b>Wrong email or password!</b></font>");
    }
    return "authorization";

}

From source file:com.itesm.test.servlets.TasksServlet.java

private void setSession(PersonaVO personaVO, HttpServletRequest request) {
    HttpSession httpSession = request.getSession();
    httpSession.setAttribute("persona", personaVO);
}

From source file:edu.harvard.hms.dbmi.bd2k.i2b2proxy.filter.SessionFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
        throws IOException, ServletException {

    String user = validateAuthorizationHeader((HttpServletRequest) req);

    if (user == null) {
        ((HttpServletResponse) res).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        res.getOutputStream().write("{\"message\":\"Session is not authorized\"}".getBytes());
        res.getOutputStream().close();/*  w  w w .  java 2  s .c  om*/
        return;
    }

    HttpSession session = ((HttpServletRequest) req).getSession();
    session.setAttribute("user", user);

    fc.doFilter(req, res);
}

From source file:jerry.c2c.action.RegisterAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
    RegisterForm userForm = (RegisterForm) form;
    String target = "message";
    ActionMessages errors = this.getErrors(request);
    MessageResources msgs = this.getResources(request);
    String messageTitle = "error";
    String messageContent = "error";
    String title = "error";
    if (userService == null) {
        target = "message";
        errors.add("fatal", new ActionMessage("errors.fatal"));
    }/*  w  w  w .ja v  a 2  s  .com*/
    User user = new User();
    try {
        BeanUtils.copyProperties(user, userForm);
        userService.save(user);
        HttpSession session = request.getSession();
        session.setAttribute("user", user);
        messageTitle = msgs.getMessage("messages.reg_success_title");
        Object[] args = new Object[2];
        args[0] = user.getName();
        args[1] = user.getId();
        messageContent = msgs.getMessage("messages.reg_success_content", args);
        title = msgs.getMessage("pagetitles.register.success");
    } catch (IllegalAccessException e) {
        errors.add("fatal", new ActionMessage("errors.fatal"));
        messageTitle = msgs.getMessage("errors.reg_fail_title");
        messageContent = msgs.getMessage("errors.reg_fail_content");
        title = msgs.getMessage("pagetitles.register.fail");
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        title = msgs.getMessage("pagetitles.register.fail");
        messageTitle = msgs.getMessage("errors.reg_fail_title");
        messageContent = msgs.getMessage("errors.reg_fail_content");
        errors.add("fatal", new ActionMessage("errors.fatal"));
        e.printStackTrace();
    } catch (BusinessException e) {
        title = msgs.getMessage("pagetitles.register.fail");
        messageTitle = msgs.getMessage("errors.reg_fail_title");
        messageContent = msgs.getMessage("errors.reg_fail_content");
        errors.add("user_exists", new ActionMessage("errors.user_exists", user.getName()));
    } finally {
        request.setAttribute("title", title);
        request.setAttribute("message_title", messageTitle);
        request.setAttribute("message_content", messageContent);
    }
    return mapping.findForward(target);
}