Example usage for javax.servlet.http HttpSession getAttribute

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

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Usage

From source file:com.ggfix.gg.user.controller.UserAuthorityController.java

@RequestMapping("/logout")
public String logout(HttpSession session) {
    User user = (User) session.getAttribute("User");
    ////www .  java 2s .  c om
    this.userManager.logout(user);
    //logout
    session.removeAttribute("User");
    session.removeAttribute("UserId");
    session.removeAttribute("UserName");
    session.removeAttribute("errorInfo");
    return "index";
}

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

@RequestMapping(value = "/contacts", method = { RequestMethod.GET })
public String getContacts(Model model, HttpServletRequest req) {
    HttpSession session = req.getSession();
    User user = (User) session.getAttribute("user");
    if (user == null) {
        model.addAttribute("authMsg", "<a href='./auth'>Log in</a>");
        model.addAttribute("exitReg", "<a href='./reg'>Register</a>");
    } else {/*from   ww  w  .j  a v  a  2 s  .  c o m*/
        model.addAttribute("authMsg", "Hello," + user.getSummonerName() + "!");
        model.addAttribute("exitReg", "<a href=.'/auth/exit'>Exit</a>");
        model.addAttribute("createbuild", "<li><a href='./add' style='color: #deff00;'>Create Build</a></li>");
    }
    return "contacts";
}

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

@RequestMapping(value = "/about", method = { RequestMethod.GET })
public String getAbout(Model model, HttpServletRequest req) {
    HttpSession session = req.getSession();
    User user = (User) session.getAttribute("user");
    if (user == null) {
        model.addAttribute("authMsg", "<a href='./auth'>Log in</a>");
        model.addAttribute("exitReg", "<a href='./reg'>Register</a>");
    } else {/*from  w w w  .ja v  a 2  s.co m*/
        model.addAttribute("authMsg", "Hello," + user.getSummonerName() + "!");
        model.addAttribute("exitReg", "<a href='./auth/exit'>Exit</a>");
        model.addAttribute("createbuild", "<li><a href='./add' style='color: #deff00;'>Create Build</a></li>");
    }
    return "about";
}

From source file:de.thm.arsnova.LoginAuthenticationSucessHandler.java

@Override
protected String determineTargetUrl(final HttpServletRequest request, final HttpServletResponse response) {
    HttpSession session = request.getSession();
    if (session == null || session.getAttribute("ars-login-success-url") == null) {
        return targetUrl;
    }/*from   w  w  w . j  a  v  a  2s .  c  om*/
    String redirect = (String) session.getAttribute("ars-login-success-url");

    return redirect;
}

From source file:br.edu.ifpb.blogsoon.webapp.controller.avaliacao.AvaliacaoController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<String> addAvaliacao(@RequestParam("idPost") String idPost,
        @RequestParam("tipo") String tipo, HttpSession session) {
    Usuario usuario = (Usuario) session.getAttribute("usuario");
    if (usuario != null) {
        if (avaliacaoService.buscarPorIdPostEUsuario(idPost, usuario).size() >= 1)
            return new ResponseEntity<>(HttpStatus.FORBIDDEN);
        Avaliacao avaliacao = new Avaliacao();
        avaliacao.setIdPost(idPost);//w w  w .  ja  va  2 s.c  o  m
        avaliacao.setUsuario(usuario);
        avaliacao.setTipo(AvaliacaoEnum.valueOf(tipo));
        avaliacaoService.salvar(avaliacao);
        return new ResponseEntity<>(HttpStatus.OK);
    }
    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:net.anthonychaves.bookmarks.web.ApiKeyController.java

@RequestMapping(method = RequestMethod.POST)
public String generateApiKey(HttpSession session, ModelMap model) {
    User user = (User) session.getAttribute("user");
    String apiKey = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16).toUpperCase();
    user = userService.setApiKey(user, apiKey);
    session.setAttribute("user", user);

    model.addAttribute("status", "success");
    model.addAttribute("newKey", apiKey);

    return "redirect:user";
}

From source file:org.owasp.webgoat.controller.About.java

/**
 * <p>welcome.</p>/*from w  ww  .  ja va 2s.  co m*/
 *
 * @param request a {@link javax.servlet.http.HttpServletRequest} object.
 * @param error a {@link java.lang.String} object.
 * @param logout a {@link java.lang.String} object.
 * @return a {@link org.springframework.web.servlet.ModelAndView} object.
 */
@RequestMapping(value = "about.mvc", method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request,
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    // set the welcome attribute
    // this is so the attack servlet does not also 
    // send them to the welcome page
    HttpSession session = request.getSession();
    if (session.getAttribute(WELCOMED) == null) {
        session.setAttribute(WELCOMED, "true");
    }

    //go ahead and send them to webgoat (skip the welcome page)
    ModelAndView model = new ModelAndView();
    //model.setViewName("welcome");
    //model.setViewName("main_new");
    model.setViewName("about");
    return model;
}

From source file:org.owasp.webgoat.controller.Welcome.java

/**
 * <p>welcome.</p>/*from w  ww.j  a  va 2 s . c  o m*/
 *
 * @param request a {@link javax.servlet.http.HttpServletRequest} object.
 * @param error a {@link java.lang.String} object.
 * @param logout a {@link java.lang.String} object.
 * @return a {@link org.springframework.web.servlet.ModelAndView} object.
 */
@RequestMapping(value = "welcome.mvc", method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request,
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    // set the welcome attribute
    // this is so the attack servlet does not also 
    // send them to the welcome page
    HttpSession session = request.getSession();
    if (session.getAttribute(WELCOMED) == null) {
        session.setAttribute(WELCOMED, "true");
    }

    //go ahead and send them to webgoat (skip the welcome page)
    ModelAndView model = new ModelAndView();
    //model.setViewName("welcome");
    //model.setViewName("main_new");
    model.setViewName("forward:/attack?start=true");
    return model;
}

From source file:mx.com.quadrum.contratos.controller.crud.EmpresaController.java

@ResponseBody
@RequestMapping(value = "eliminarEmpresa", method = RequestMethod.POST)
public String eliminarEmpresa(Empresa empresa, BindingResult bindingResult, HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }//from   ww  w. ja v  a 2  s.  c  o  m
    return empresaService.eliminar(empresa);
}

From source file:edu.lafayette.metadb.web.authentication.CheckSession.java

public boolean checkUser(HttpSession session) {
    if (session.getAttribute(Global.SESSION_USERNAME) == null)
        return false;
    return MetaDbHelper.userExists((String) session.getAttribute(Global.SESSION_USERNAME));
}