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.web.controller.concept.ConceptStopWordFormControllerTest.java

/**
 * @see {@link ConceptStopWordFormController#handleSubmission(HttpSession, ConceptStopWordFormBackingObject, org.springframework.validation.BindingResult)
 *//*from  w  ww . ja va2  s .c  om*/
@Test
@Verifies(value = "should add new ConceptStopWord", method = "handleSubmission(HttpSession, ConceptStopWordFormBackingObject, BindingResult)")
public void handleSubmission_shouldAddNewConceptStopWord() throws Exception {
    ConceptStopWordFormController controller = (ConceptStopWordFormController) applicationContext
            .getBean("conceptStopWordFormController");

    HttpSession mockSession = new MockHttpSession();

    mockSession.setAttribute("value", "As");
    BindException errors = new BindException(new ConceptStopWord("As", Locale.ENGLISH), "value");

    controller.handleSubmission(mockSession, new ConceptStopWord("As", Locale.ENGLISH), errors);

    Assert.assertEquals("ConceptStopWord.saved", mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    Assert.assertNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR));
}

From source file:org.openmrs.module.dms.web.controller.main.DeActivatedUnitListController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, HttpServletRequest request) {
    DmsService dmsService = Context.getService(DmsService.class);
    DmsOpdUnit dmsopdunit = new DmsOpdUnit();
    String select[] = request.getParameterValues("showResultsn");
    if (select != null && select.length != 0) {
        for (int i = 0; i < select.length; i++) {
            Integer unitid = Integer.parseInt(select[i]);
            dmsopdunit = dmsService.getDmsOpd(unitid);
            dmsopdunit.setUnitActiveDate(new Date());
            dmsopdunit.setUnitDeactiveDate(null);
            dmsService.saveOrUpdateUnit(dmsopdunit);
        }//from w w w.j  av a2  s .c  o  m
    }

    HttpSession httpSession = request.getSession();

    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "dms.activate.success");
    return "redirect:/module/dms/deActivatedUnitList.form";
}

From source file:org.openmrs.module.dms.web.controller.main.DeActivateUnitController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, HttpServletRequest request) {
    DmsService dmsService = Context.getService(DmsService.class);
    DmsOpdUnit dmsopdunit = new DmsOpdUnit();
    String select[] = request.getParameterValues("showResultsn");
    if (select != null && select.length != 0) {
        for (int i = 0; i < select.length; i++) {
            Integer unitid = Integer.parseInt(select[i]);
            dmsopdunit = dmsService.getDmsOpd(unitid);
            dmsopdunit.setUnitActiveDate(null);
            dmsopdunit.setUnitDeactiveDate(new Date());
            dmsService.saveOrUpdateUnit(dmsopdunit);
        }//from w  ww.j  a  v a 2 s.  c  om
    }

    HttpSession httpSession = request.getSession();

    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "dms.deactivate.success");
    return "redirect:/module/dms/deActivateUnit.form";
}

From source file:com.naver.timetable.bo.LoginBO.java

/**
 * ? ?  /*  w  w  w.  j  a  va  2 s.c o  m*/
 * pw ?   
 * @param request
 * @param user
 * @param pw
 */
@Transactional
public void join(User user, HttpServletRequest request) {

    userDAO.join(user);

    user = userDAO.login(user.getStudentNum());
    HttpSession session = request.getSession();
    session.setAttribute("user", user);
}

From source file:net.thewaffleshop.passwd.security.AuthenticationHandler.java

/**
 * Successful login; send the redirect URL
 *
 * @param request//from   w  w w  .jav  a 2 s  .com
 * @param response
 * @param authentication
 * @throws IOException
 * @throws ServletException
 */
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    AccountAuthenticationToken auth = (AccountAuthenticationToken) authentication;

    HttpSession session = request.getSession();
    session.setAttribute("account", auth.getAccount());
    session.setAttribute("secretKey", auth.getSecretKey());

    String url = ServletUriComponentsBuilder.fromContextPath(request).path(TARGET_URL).build().toUriString();

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json");
    response.getWriter().write("{\"success\": true, \"url\": \"" + StringEscapeUtils.escapeJson(url) + "\"}");
}

From source file:org.sventon.web.ctrl.ConfigurationLoginController.java

@Override
protected ModelAndView onSubmit(final HttpServletRequest request, final HttpServletResponse response,
        final Object command, final BindException errors) throws Exception {

    final ConfigLoginCommand configLoginCommand = (ConfigLoginCommand) command;
    final String passwordString = configLoginCommand.getUserPassword();

    if (application.isValidConfigPassword(passwordString)) {
        logger.debug("Correct config password entered");
        final HttpSession session = request.getSession();
        session.setAttribute("isAdminLoggedIn", true);
        return super.onSubmit(configLoginCommand, errors);
    } else {/*w  ww  .  j  a va 2  s .c  o m*/
        logger.debug("Incorrect config password entered");
        errors.rejectValue("userPassword", "illegal.config.password", "Illegal config password");
        return super.showForm(request, response, errors);
    }
}

From source file:org.mitre.openid.connect.web.AuthenticationTimeStamper.java

/**
 * Set the timestamp on the session to mark when the authentication happened,
 * useful for calculating authentication age. This gets stored in the sesion
 * and can get pulled out by other components.
 *///  w ww  .ja v  a2  s . c  o m
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    Date authTimestamp = new Date();

    HttpSession session = request.getSession();

    session.setAttribute(AUTH_TIMESTAMP, authTimestamp);

    if (session.getAttribute(AuthorizationRequestFilter.PROMPT_REQUESTED) != null) {
        session.setAttribute(AuthorizationRequestFilter.PROMPTED, Boolean.TRUE);
        session.removeAttribute(AuthorizationRequestFilter.PROMPT_REQUESTED);
    }

    logger.info("Successful Authentication of " + authentication.getName() + " at " + authTimestamp.toString());

    super.onAuthenticationSuccess(request, response, authentication);

}

From source file:com.hillert.botanic.controller.AuthenticationController.java

@RequestMapping(value = "/authenticate", method = { RequestMethod.POST })
public AuthenticationToken authorize(@RequestBody AuthenticationRequest authenticationRequest,
        HttpServletRequest request) {//from   ww  w.j a  va 2  s  .co  m

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            authenticationRequest.getUsername(), authenticationRequest.getPassword());
    Authentication authentication = this.authenticationManager.authenticate(token);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    HttpSession session = request.getSession(true);
    session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
            SecurityContextHolder.getContext());

    UserDetails details = this.userDetailsService.loadUserByUsername(authenticationRequest.getUsername());

    final Map<String, Boolean> roles = new HashMap<String, Boolean>();

    for (GrantedAuthority authority : details.getAuthorities()) {
        roles.put(authority.toString(), Boolean.TRUE);
    }

    return new AuthenticationToken(details.getUsername(), roles, session.getId());
}

From source file:org.openmrs.module.sdmxhdintegration.web.controller.MessageAttributesController.java

/**
 * Handles form submission/* w  w  w . java 2s. com*/
 * @param request the request object
 * @param message the message from the model
 * @param result the binding result
 * @return the view
 */
@RequestMapping(method = RequestMethod.POST)
public String handleSubmission(HttpServletRequest request, @ModelAttribute("message") SDMXHDMessage message,
        BindingResult result) {

    SDMXHDService service = Context.getService(SDMXHDService.class);
    service.saveMessage(message);

    HttpSession session = request.getSession();
    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Global message configuration saved");
    return "redirect:messages.list";
}

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

@RequestMapping(params = "command=login")
public String login(HttpSession session, @RequestParam("username") String username, Model model) {
    session.setAttribute("username", username);
    msgPublisher.login(username);//from  ww w.ja  v a2 s.  c  o  m
    Set<String> loginUsers = (Set<String>) msgPublisher.getLoginUsers();
    loginUsers.remove(username);
    model.addAttribute("loginUsers", loginUsers);

    return "chat";
}