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();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:com.sishuok.chapter3.web.controller.chat.ChatController.java

@RequestMapping(params = "command=send")
@ResponseBody//from   w  ww.j a v a 2 s.  c  om
private void send(final HttpServletRequest req) {
    String sender = (String) req.getSession().getAttribute("username");
    String receiver = req.getParameter("receiver");
    String msg = req.getParameter("msg");
    msgPublisher.send(receiver, sender, msg);
}

From source file:com.uniquesoft.uidl.servlet.UploadServlet.java

/**
 * Return the most recent list of FileItems received
 */// w  w  w  . j  av a 2s  .  c o  m
@SuppressWarnings("unchecked")
public static List<FileItem> getLastReceivedFileItems(HttpServletRequest request, String sessionLastFilesKey) {
    return (List<FileItem>) request.getSession().getAttribute(sessionLastFilesKey);
}

From source file:com.tce.oauth2.spring.client.controller.UserInfoController.java

@RequestMapping("/userinfo")
public String index(HttpServletRequest request) {
    if (request.getSession().getAttribute("access_token") == null) {
        return "redirect:/";
    }/* w ww  . j a v  a 2 s. c  o m*/

    String accessToken = (String) request.getSession().getAttribute("access_token");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Bearer " + accessToken);
    HttpEntity<?> entity = new HttpEntity<>(headers);

    ResponseEntity<User> response = restTemplate.exchange(OAUTH_URL + "/userinfo", HttpMethod.GET, entity,
            User.class);

    if (response.getStatusCode().is4xxClientError()) {
        return "redirect:/login";
    }

    User user = response.getBody();
    request.getSession(false).setAttribute("username", user.getUsername());
    return "redirect:/";
}

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

@Override
@SuppressWarnings("unchecked")
public PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails buildDetails(HttpServletRequest request) {
    if (request.getSession().getAttribute(authoritiesSessionAttribute) != null) {
        List<String> authorities = (List<String>) request.getSession()
                .getAttribute(authoritiesSessionAttribute);
        Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
        for (String authority : authorities) {
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(authority);
            grantedAuthorities.add(grantedAuthority);
        }//from  ww w  .  j av  a  2 s.c o  m
        PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails details = new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(
                request, grantedAuthorities);
        return details;
    } else {
        GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("NO_AUTHORITY");
        Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
        grantedAuthorities.add(grantedAuthority);
        PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails details = new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(
                request, grantedAuthorities);
        return details;
    }
}

From source file:edu.zipcloud.cloudstreetmarket.api.controllers.SessionController.java

@RequestMapping(value = "/current", method = DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)/*from  w  w  w  .  j a  v a2 s  .  com*/
@ApiOperation(value = "Invalidate the user Session")
public void logout(HttpServletRequest request) {
    request.getSession().invalidate();
}

From source file:org.openmrs.module.phrjournal.web.controller.NewEntryController.java

@RequestMapping(value = "/module/phrjournal/new_entry")
public void populateModel(HttpServletRequest request) {
    if (shouldReset) {
        request.getSession().setAttribute("content", "");
        request.getSession().setAttribute("title", "");
    } else {//from  w  ww . ja  v  a2 s  .  c  o m
        shouldReset = true;
    }
}

From source file:com.acc.controller.LogoutController.java

/**
 * Spring security logout successful redirect.
 *//*from  w  w  w  .  ja  v a2s. c om*/
@RequestMapping(value = "/current/logout", method = RequestMethod.POST)
@ResponseBody
public LogoutResponse logout(final HttpServletRequest request) {
    JaloSession.getCurrentSession().close();
    request.getSession().invalidate();
    final LogoutResponse logoutResponse = new LogoutResponse();
    logoutResponse.setSuccess(true);
    return logoutResponse;
}

From source file:com.lynn.controller.LoginAction.java

@RequestMapping("/login/success.do")
public ModelAndView loginSuccess(HttpServletRequest request) {
    UserBean user = (UserBean) request.getSession().getAttribute("user");
    ModelAndView mv = new ModelAndView();
    if (user == null) {
        mv.setViewName("redirect:/login.jsp");
        return mv;
    }//from w w  w . j a  v a 2 s .co m
    mv.addObject("username", user.getUsername());
    mv.setViewName("login_success");
    return mv;
}

From source file:com.lioland.harmony.web.controller.DefaultController.java

@RequestMapping(method = RequestMethod.POST, value = "/logout")
public String logout(HttpServletRequest request) {
    request.getSession().invalidate();
    return "redirect:home";
}

From source file:com.moderndrummer.controller.VideosController.java

/***
 * #TODO/*  w w w.  j  a  v a2 s .c  om*/
 * 
 * @param model
 * @param request
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public String displayVideos(Model model, HttpServletRequest request) {
    Member loggedMember = (Member) request.getSession().getAttribute("loggedUser");
    if (ObjectUtil.verifyMemberExists(loggedMember)) {
        return "videos";
    } else {
        return "redirect:login";
    }

}