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:br.com.everson.clei.springmvc.controller.ClienteController.java

@RequestMapping("/selecionarCliente ")
public String importarClienteNoSession(HttpServletRequest hsr, HttpSession hs, Cliente c, Model m) {
    hs.setAttribute("clienteAtual", clientes.get(Integer.parseInt(hsr.getParameter("id"))));
    return "redirect:painelDoCliente";
}

From source file:controller.HelpController.java

@RequestMapping(value = "/reset-password", method = RequestMethod.POST)
public String login(@ModelAttribute(value = "user") User user, ModelMap map, HttpSession session) {
    if (user.getUsername().equals("vupa")) {
        session.setAttribute("username", user.getUsername());
        return "redirect:/";
    } else {/*ww  w .j a  v  a2s. c o m*/
        return "error";
    }
}

From source file:edu.ijse.tcd.controller.LogInController.java

@RequestMapping(value = "addLogIn", method = RequestMethod.POST)
public String addLogIn(ModelMap map, HttpServletRequest request) {

    String username = request.getParameter("username");
    String password = request.getParameter("password");

    User user = signInService.getUser(username, password);

    if (null != user) {
        HttpSession hs = request.getSession();
        hs.setAttribute("user", user);
        return "adminPannel";
    } else {/* w ww  .j a va2  s  .  co m*/
        return "login";
    }
}

From source file:com.havoc.hotel.admin.controller.DefaultController.java

@RequestMapping(method = RequestMethod.POST, value = "checking")
public String filter(HttpServletRequest req, HttpServletResponse res) {
    String username = req.getParameter("username");
    String password = req.getParameter("password");
    User user = userDAO.authenticate(username, password);
    if (user == null) {
        return "admin/login";
    } else {/* w  w w  .  j  a v a  2  s  . c  o  m*/
        HttpSession session = req.getSession();
        session.setAttribute("username", username);
        if (user.getRoleId() == 1) {
            return "admin/dashboard/dashboard";

        } else {

            return "admin/dashboard/dashboarduser";
        }

    }

}

From source file:com.iterzp.momo.service.impl.RSAServiceImpl.java

@Override
@Transactional(readOnly = true)//w ww .  j a v  a  2  s. c  o m
public RSAPublicKey generateKey(HttpServletRequest request) {
    Assert.notNull(request);
    KeyPair keyPair = RSAUtils.generateKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
    HttpSession session = request.getSession();
    session.setAttribute(PRIVATE_KEY_ATTRIBUTE_NAME, privateKey);
    return publicKey;
}

From source file:org.hbr.mongo.session.controller.SessionController.java

/**
 * Test the Session/*  w  ww.java 2  s .c o m*/
 * @return
 */
@RequestMapping(value = "/get-session", method = RequestMethod.GET)
public ModelAndView getSession(HttpSession session) {
    /* add a property to the session */
    session.setAttribute("TEST", "TEST");
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("id", session.getId());
    return new ModelAndView("displaySession", model);
}

From source file:net.thewaffleshop.nimbus.security.ForwardingAuthenticationHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    // extract account and password
    String password = (String) authentication.getCredentials();
    AccountUser accountUser = (AccountUser) authentication.getPrincipal();
    Account account = accountUser.getAccount();
    // decode the secret key
    SecretKey secretKey = accountAPI.getSecretKey(account, password);
    // store the account and secret key in the session
    HttpSession session = request.getSession();
    session.setAttribute("account", account);
    session.setAttribute("secretKey", secretKey);

    // forward request to success MVC method
    request.getRequestDispatcher("/authenticationSuccess").forward(request, response);
}

From source file:org.meruvian.yama.web.DefaultCredentialsService.java

@Override
public void registerAuthentication(String userId, HttpServletRequest request) {
    User user = userRepository.findById(userId);
    UserDetails userDetails = userDetailsService.loadUserByUsername(user.getUsername());

    Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, null,
            userDetails.getAuthorities());
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);

    HttpSession session = request.getSession(true);
    session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
}

From source file:controleur.moncompte.CmdEssaiConnexion.java

@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {

    REST_Utilisateur ru = new REST_Utilisateur();
    Boolean connecte = Boolean.valueOf(ru.verifier(String.class, request.getParameter("identifiant"),
            DigestUtils.sha1Hex(request.getParameter("password"))));
    if (connecte) {
        Connexion connexion = new Connexion();
        connexion.setConnexion(true);/*w  w w.  j  a v  a 2 s  .  c o m*/
        Utilisateur utilisateur;
        utilisateur = ru.findByLogin_JSON(Utilisateur.class, request.getParameter("identifiant"));
        HttpSession httpSession = request.getSession(false);
        httpSession.setAttribute("connexion", connexion);
        httpSession.setAttribute("utilisateur", utilisateur);
        return "WEB-INF/accueil.jsp";
    } else {
        String erreur = "Erreur identification";
        request.setAttribute("erreur", erreur);
        request.setAttribute("identifiant", request.getParameter("identifiant"));
        request.setAttribute("password", request.getParameter("password"));
        return "WEB-INF/connexion.jsp";
    }
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    // Get the current session object, create one if necessary
    HttpSession session = req.getSession();

    // Add a CustomBindingListener
    session.setAttribute("bindings.listener", new CustomBindingListener(getServletContext()));

    out.println("This page intentionally left blank");
}