Example usage for javax.servlet.http HttpSession removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes the object bound with the specified name from this session.

Usage

From source file:id.ac.ipb.ilkom.training.controller.LoginController.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(HttpSession session, Model model) {
    String errorMessage = (String) session.getAttribute("errorMessage");
    if (errorMessage != null && errorMessage.trim().length() > 0) {
        model.addAttribute("errorMessage", errorMessage);
        //remove attribute from session
        session.setAttribute("errorMessage", null);
        session.removeAttribute("errorMessage");
    }/*from  w  w w  .j a  va2s.com*/
    return "login";
}

From source file:dk.itst.oiosaml.sp.service.session.SingleVMSessionHandler.java

public void logOut(HttpSession session) {
    // We cannot remove the SESSION_ID_LIST since we use it in LogoutHttpResponseServlet
    // session.removeAttribute(Constants.SESSION_ID_LIST);
    removeAssertion(session.getId());//ww  w  .  ja va  2 s  . co m
    session.removeAttribute(Constants.SESSION_USER_ASSERTION);
}

From source file:org.duracloud.account.app.controller.AccountGroupsControllerTest.java

@Test
public void testSaveGroup() throws Exception {
    expectGroupGroups(1);// www.  j av  a  2  s. c om

    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    HttpSession session = EasyMock.createMock(HttpSession.class);
    EasyMock.expect(request.getSession()).andReturn(session).once();

    session.removeAttribute(AccountGroupsController.GROUP_USERS_KEY);
    EasyMock.expectLastCall().once();

    EasyMock.expect(session.getAttribute(AccountGroupsController.GROUP_USERS_KEY)).andReturn(null).once();

    session.setAttribute(EasyMock.anyObject(String.class), (Collection<DuracloudUser>) EasyMock.anyObject());
    EasyMock.expectLastCall().once();

    this.groupService.updateGroupUsers(EasyMock.anyObject(DuracloudGroup.class),
            (Set<DuracloudUser>) EasyMock.anyObject(), EasyMock.anyLong());
    EasyMock.expectLastCall().once();

    EasyMock.replay(request, session);

    replayMocks();

    GroupForm form = new GroupForm();
    form.setAction(GroupForm.Action.SAVE);

    String view = this.accountGroupsController.editGroup(accountId, DuracloudGroup.PREFIX + TEST_GROUP_NAME,
            form, request, model);
    Assert.assertTrue(view.contains(TEST_GROUP_NAME));
    Assert.assertFalse(view.endsWith("edit"));

    Assert.assertNotNull(getModelAttribute(AccountGroupsController.GROUP_KEY));
    Assert.assertNotNull(getModelAttribute(AccountGroupsController.GROUP_USERS_KEY));

}

From source file:com.lm.lic.manager.service.HibernateLoginService.java

/**
 * @param username/*  www  .  j  av a  2s .c o m*/
 * @param loggedin
 * @param user
 * @param httpSession
 */
public void makeUserLoggedOut(User user, HttpSession httpSession) {
    httpSession.setAttribute(GenUtil.LOGGED_IN_ATTRIBUTE, false);

    httpSession.removeAttribute("user");

    httpSession.removeAttribute(GenUtil.LOGGED_IN_ATTRIBUTE);
    httpSession.removeAttribute(GenUtil.ROLE_ATTRIBUTE);
    httpSession.removeAttribute(GenUtil.LOGGED_IN_USER_ATTRIBUTE);
    httpSession.removeAttribute("user");
    httpSession.removeAttribute("home");
    httpSession.removeAttribute("userTypeRoleId");
    httpSession.removeAttribute("userTypeRoleObj");
    httpSession.removeAttribute("aclContext");

    removeLoggedinUser(user.getUsername());
}

From source file:com.linecorp.sample.login.core.application.controller.WebController.java

/**
 * <p>Redirect Page from LINE Platform</p>
 * <p>Login Type is to log in on any desktop or mobile website
 * https://developers.line.me/web-login/integrating-web-login#redirect_to_web_site
 *///from  w w  w .  j  a  v a2 s . c  o m
@RequestMapping("/auth")
public ModelAndView auth(HttpSession httpSession, @RequestParam(value = "state") String state,
        @RequestParam(value = "code") String code) {

    if (!state.equals(httpSession.getAttribute(LINE_WEB_LOGIN_STATE))) {
        throw new IllegalArgumentException();
    }
    ;
    httpSession.removeAttribute(LINE_WEB_LOGIN_STATE);
    if (logger.isDebugEnabled()) {
        logger.debug("code : " + code);
    }
    AccessToken token = lineAPIService.accessToken(code);
    if (logger.isDebugEnabled()) {
        logger.debug("mid : " + token.mid);
        logger.debug("access_token : " + token.access_token);
        logger.debug("refresh_token : " + token.refresh_token);
        logger.debug("expires_in : " + token.expires_in);
    }

    httpSession.setAttribute(ACCESS_TOKEN, token);

    ModelAndView mav = new ModelAndView("user/success");
    mav.addObject("token", token);

    return mav;
}

From source file:be.fedict.eid.dss.protocol.simple.client.SignatureResponseProcessorServlet.java

/**
 * Clears the used session attributes. Also returns a reference to the
 * previously signed document./* w w  w . j  a  va2s . co m*/
 * 
 * @param httpSession
 *            the http session
 * @return reference to previously signed document
 */
private byte[] clearAllSessionAttribute(HttpSession httpSession) {
    httpSession.removeAttribute(this.errorMessageSessionAttribute);
    byte[] signedDocument = (byte[]) httpSession.getAttribute(this.signedDocumentSessionAttribute);
    httpSession.removeAttribute(this.signedDocumentSessionAttribute);
    if (null != this.signatureCertificateSessionAttribute) {
        httpSession.removeAttribute(this.signatureCertificateSessionAttribute);
    }
    return signedDocument;
}

From source file:de.hybris.telcotrail.storefront.controllers.pages.AbstractLoginPageController.java

protected String getDefaultLoginPage(final boolean loginError, final HttpSession session, final Model model)
        throws CMSItemNotFoundException {
    final LoginForm loginForm = new LoginForm();
    model.addAttribute(loginForm);//from ww w  .  j  a va 2  s  .  c  om
    model.addAttribute(new RegisterForm());

    final String username = getUsernameTryingToLogin(session);
    if (username != null) {
        session.removeAttribute(SPRING_SECURITY_LAST_USERNAME);
    }

    loginForm.setJ_username(username);
    storeCmsPageInModel(model, getCmsPage());
    setUpMetaDataForContentPage(model, (ContentPageModel) getCmsPage());
    model.addAttribute("metaRobots", "index,no-follow");

    final Breadcrumb loginBreadcrumbEntry = new Breadcrumb("#",
            getMessageSource().getMessage("header.link.login", null, getI18nService().getCurrentLocale()),
            null);
    model.addAttribute("breadcrumbs", Collections.singletonList(loginBreadcrumbEntry));

    if (loginError) {
        GlobalMessages.addErrorMessage(model, "login.error.account.not.found.title");
    }
    return getView();
}

From source file:egpi.tes.ahv.servicio.AutenticacionREST.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {/*from  w  w  w  .  ja  va2 s . c  om*/

        HttpSession session = request.getSession(true);
        session.setAttribute("clientjasper", this.client);
        session.setAttribute("propiedadesjasper", this.properties);
        session.removeAttribute("authVO");

        autenticacionUsuarioGeneral();

        PrintWriter out = response.getWriter();
        out.println(obj);

    } catch (Exception e) {
        e.printStackTrace();
        procesarError(response, e);
    }

}

From source file:com.lewischooman.services.EmployeeSrv.java

@Override
public boolean login(HttpSession httpSession, String uid, String password) {
    EmployeeDB employee = this.employeeDAO.getUserByLoginName(uid);
    if (employee != null && this.digester.digestToHex(password).equals(employee.getPassword())) {
        httpSession.setAttribute(Utility.LOGGED_IN_USER_ATTRIBUTE, employee);
        return true;
    } else {/*from  ww  w  .jav  a  2s. com*/
        httpSession.removeAttribute(Utility.LOGGED_IN_USER_ATTRIBUTE);
        return false;
    }
}

From source file:handlers.CustomLoginSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    this.setDefaultTargetUrl(defaultSuccessUrl);
    String username = ((User) authentication.getPrincipal()).getUsername();
    userService.updateLastLoginAccess(username, new Date());
    HttpSession session = request.getSession();
    if (session != null) {
        String redirectUrl = (String) session.getAttribute("url_prior_login");
        if (redirectUrl != null) {
            logger.info("Redirigiendo usuario a : " + redirectUrl);
            // we do not forget to clean this attribute from session
            session.removeAttribute("url_prior_login");
            // then we redirect
            getRedirectStrategy().sendRedirect(request, response, redirectUrl);
        } else {//w  w w .  j av a 2  s  . co m
            super.onAuthenticationSuccess(request, response, authentication);
        }
    } else {
        super.onAuthenticationSuccess(request, response, authentication);
    }
}