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:io.lavagna.web.helper.UserSession.java

public static void setUser(int userId, boolean isUserAnonymous, HttpServletRequest req,
        HttpServletResponse resp, UserRepository userRepository, boolean addRememberMeCookie) {

    req.getSession().invalidate();//  w w  w.jav a 2  s.co m
    if (addRememberMeCookie) {
        addRememberMeCookie(userId, req, resp, userRepository);
    }
    HttpSession session = req.getSession(true);
    session.setAttribute(AUTH_KEY, true);
    session.setAttribute(AUTH_USER_ID, userId);
    session.setAttribute(AUTH_USER_IS_ANONYMOUS, isUserAnonymous);
    session.setAttribute(AUTH_LOCKED, false);
}

From source file:org.openxdata.server.servlet.MultimediaServlet.java

public static void clearFormSessionData(HttpServletRequest request, String formId) {
    HttpSession session = request.getSession();
    session.setAttribute(getFormKey(formId), null);
}

From source file:org.keycloak.example.CustomerDatabaseClient.java

public static String increaseAndGetCounter(HttpServletRequest req) {
    HttpSession session = req.getSession();
    Integer counter = (Integer) session.getAttribute("counter");
    counter = (counter == null) ? 1 : counter + 1;
    session.setAttribute("counter", counter);
    return String.valueOf(counter);
}

From source file:be.fedict.eid.applet.service.impl.handler.SignatureDataMessageHandler.java

public static void setDigestValue(byte[] digestValue, String digestAlgo, HttpSession session) {
    session.setAttribute(DIGEST_VALUE_SESSION_ATTRIBUTE, digestValue);
    session.setAttribute(DIGEST_ALGO_SESSION_ATTRIBUTE, digestAlgo);
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.java

/**
 * Store this login process bean in the session.
 *///from  w w w.ja  va  2 s.  com
public static void setBean(HttpServletRequest request, LoginProcessBean bean) {
    HttpSession session = request.getSession();
    session.setAttribute(SESSION_ATTRIBUTE, bean);
}

From source file:info.magnolia.cms.security.Authenticator.java

/**
 * Authenticate authorization request using JAAS login module as configured
 * @param request as received by the servlet engine
 * @return boolean//from ww w  .jav a2 s.c  o m
 */
public static boolean authenticate(HttpServletRequest request) {
    String credentials = request.getHeader("Authorization");
    String userid;
    String pswd;
    CredentialsCallbackHandler callbackHandler;
    String loginModuleToInitialize = "magnolia"; // default login module

    if (StringUtils.isEmpty(credentials) || credentials.length() <= 6) {
        // check for form based login request
        if (StringUtils.isNotEmpty(request.getParameter(PARAMETER_USER_ID))) {
            userid = request.getParameter(PARAMETER_USER_ID);
            pswd = StringUtils.defaultString(request.getParameter(PARAMETER_PSWD));
            callbackHandler = new PlainTextCallbackHandler(userid, pswd.toCharArray());
        } else {
            // select login module to use if user is authenticated against the container
            if (request.getUserPrincipal() != null) {
                loginModuleToInitialize = "magnolia_authorization";
                callbackHandler = new PlainTextCallbackHandler(request.getUserPrincipal().getName(),
                        "".toCharArray());
            } else {
                // invalid auth request
                return false;
            }
        }
    } else {
        // its a basic authentication request
        callbackHandler = new Base64CallbackHandler(credentials);
    }

    Subject subject;
    try {
        LoginContext loginContext = new LoginContext(loginModuleToInitialize, callbackHandler);
        loginContext.login();
        subject = loginContext.getSubject();
        // ok, we NEED a session here since the user has been authenticated
        HttpSession httpsession = request.getSession(true);
        httpsession.setAttribute(ATTRIBUTE_JAAS_SUBJECT, subject);
    } catch (LoginException le) {
        if (log.isDebugEnabled())
            log.debug("Exception caught", le);

        HttpSession httpsession = request.getSession(false);
        if (httpsession != null) {
            httpsession.invalidate();
        }
        return false;
    }

    return true;
}

From source file:com.jdon.strutsutil.FormBeanUtil.java

/**
 * ActionForm?struts_config.xmlattribute
 * //from   w  w  w  .  j a  v a2 s  .  co  m
 * @param form
 * @param mapping
 * @param request
 */
public static void saveActionForm(ActionForm form, ActionMapping mapping, HttpServletRequest request) {
    if ((form != null) && (mapping.getAttribute() != null)) {
        if ("request".equals(mapping.getScope())) {
            request.setAttribute(mapping.getAttribute(), form);
        } else {
            HttpSession session = request.getSession();
            session.setAttribute(mapping.getAttribute(), form);
            request.setAttribute(mapping.getAttribute(), form);
        }
    }
}

From source file:modelo.AutenticacionManager.Autenticacion.java

private static void variablesSession(HttpSession sesion, HttpServletResponse response, String login, String rol,
        String ip) {/*w  ww .j a  v a2 s . c o m*/

    //public static void variablesSession(HttpSession sesion, String login, String ip, String rol, String persona, String codigoPersona) {
    sesion.setAttribute("login", login);
    sesion.setAttribute("ip", ip);

    Cookie ssocookie = new Cookie("login", encode(login));
    ssocookie.setPath("/");
    response.addCookie(ssocookie);

    ssocookie = new Cookie("ip", encode(ip));
    ssocookie.setPath("/");
    response.addCookie(ssocookie);

    /*ssocookie = new Cookie("rol", encode(rol));
    ssocookie.setPath("/");
    response.addCookie(ssocookie);*/

}

From source file:com.swdouglass.joid.server.OpenIdServlet.java

/**
 * This sets a session variable stating that the claimed_id for this request
 * has been verified so we can now return back to the relying party.
 *
 * @param session//  w ww  .  ja  v  a 2s . c  o  m
 * @param claimedId
 */
public static void idClaimed(HttpSession session, String claimedId) {
    session.setAttribute(ID_CLAIMED, claimedId);
}

From source file:net.webpasswordsafe.server.ServerSessionUtil.java

public static void initCsrfSession() {
    HttpSession session = getRequest().getSession(false);
    if (session.isNew() || (session.getAttribute(Constants.CSRF_TOKEN_KEY) == null)) {
        // either new session or old session without csrf token set, so set it
        session.setAttribute(Constants.CSRF_TOKEN_KEY, session.getId());
        Cookie cookie = new Cookie(Constants.CSRF_TOKEN_KEY, session.getId());
        cookie.setPath("".equals(getRequest().getContextPath()) ? "/" : getRequest().getContextPath());
        getResponse().addCookie(cookie);
    }/*from www . j a  v  a 2s  .  c om*/
}