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.swiftcorp.portal.common.util.WebUtils.java

public static String getUniqueCode(HttpServletRequest request) {
    HttpSession session = request.getSession();
    LoginDetailInfoDTO loginInfo = (LoginDetailInfoDTO) session.getAttribute(SESSION_KEYS.LOGIN_INFO);
    return loginInfo.getUser().getUniqueCode();
}

From source file:de.dominikschadow.javasecurity.csrf.CSRFTokenHandler.java

public static String getToken(HttpSession session)
        throws ServletException, NoSuchAlgorithmException, NoSuchProviderException {
    if (session == null) {
        throw new ServletException(MISSING_SESSION);
    }/* w  ww  .  ja  v a2 s .  c  om*/

    String token = (String) session.getAttribute(CSRF_TOKEN);

    if (StringUtils.isEmpty(token)) {
        token = getToken();
        session.setAttribute(CSRF_TOKEN, token);
    }

    return token;
}

From source file:org.sloth.util.ControllerUtils.java

/**
 * Gets the {@code User} in the specified {@code HttpSession}
 * // w w w.  java  2 s .com
 * @param s
 *            the session
 * @return the {@code User} or {@code null} if {@code s} is not authorized
 */
public static User getUser(HttpSession s) {
    Object o = s.getAttribute(SESSION_ATTRIBUTE);
    if (o != null && o instanceof User) {
        return (User) o;
    } else {
        return null;
    }
}

From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java

public static void terminateSession(HttpSession httpSession) {
    if (httpSession != null) {
        if ("true".equals("" + httpSession.getAttribute("administration"))) {
            httpSession.setMaxInactiveInterval(1);
        }//from   www . j av  a  2  s . c  o  m
    }
}

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

/**
 * @param request current HttpServletRequest
 * @return String , current logged in user
 *//*www  .  j a v  a2s. c o  m*/
public static String getUserId(HttpServletRequest request) {
    String userId = null;

    HttpSession httpsession = request.getSession(false);
    if (httpsession != null) {
        userId = (String) httpsession.getAttribute(ATTRIBUTE_USER_ID);
    }

    if (userId == null) {
        String credentials = request.getHeader("Authorization");
        if (credentials != null) {
            try {
                userId = getDecodedCredentials(credentials.substring(6).trim());
                if (httpsession != null) {
                    httpsession.setAttribute(ATTRIBUTE_USER_ID, userId);
                }
            } catch (Exception e) {
                log.debug(e.getMessage(), e);
            }
        }
    }

    return userId;
}

From source file:com.swiftcorp.portal.common.util.WebUtils.java

public static Long getLoggedInUserId(HttpServletRequest request) {
    HttpSession session = request.getSession();
    LoginDetailInfoDTO loginInfo = (LoginDetailInfoDTO) session.getAttribute(SESSION_KEYS.LOGIN_INFO);
    Long userId = null;//from   w w w . java2  s  .c  o m

    if (loginInfo != null) {
        userId = loginInfo.getUser().getComponentId();
    }

    if (userId == null) {
        // for initial phase assuming this is as default case
        userId = new Long(1);
    }

    return userId;
}

From source file:be.fedict.eid.dss.webapp.ProtocolEntryServlet.java

/**
 * @param httpSession/*from  w  ww  .  j ava2s . c om*/
 *            the HTTP session
 * @return the protocol service context path that was used during entry of
 *         the eID DSS.
 */
public static String retrieveProtocolServiceEntryContextPath(HttpSession httpSession) {
    return (String) httpSession.getAttribute(PROTOCOL_SERVICE_CONTEXT_PATH_SESSION_ATTRIBUTE);
}

From source file:com.bsb.cms.commons.web.MossActionUtils.java

/**
 * ??//w w w .  j ava2  s .  c om
 * 
 * @return
 */
public static boolean isAdmin(HttpSession session) {
    Boolean isAdmin = false;
    String userName = (String) session.getAttribute(USER_NAME);
    if ("admin".equalsIgnoreCase(userName)) {
        isAdmin = true;
    }

    return isAdmin;
}

From source file:ke.alphacba.cms.core.util.NoSessionIdUtils.java

public static BaseResp writeCookie(HttpSession session, HttpServletRequest request,
        HttpServletResponse response, String loginCookieName, String domain, int cookieTime) {
    BaseResp baseResp = new BaseResp();
    String jsessionId = (String) session.getAttribute("jsessionId");
    try {//from   w  w w  . j a  v  a  2  s.  c  o  m
        Cookie[] cookies = request.getCookies();
        if (cookies == null) {
            baseResp.setErrorNo(ErrorNoConstants.ERR_COM_ERRORINFO, "??");
            return baseResp;
        }
        boolean flag = false;
        boolean httpOnly = true;
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals(loginCookieName)) {
                if (StringUtils.isEmpty(cookies[i].getValue())) {
                    writeCookie(response, loginCookieName, domain, cookieTime, jsessionId, httpOnly);
                }
                flag = true;
            }
        }
        if (!flag) {
            writeCookie(response, loginCookieName, domain, cookieTime, jsessionId, httpOnly);
        }
    } catch (Exception e) {
        log.error("write cookie store error !", e);
    }
    return baseResp;
}

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

/**
 * ?struts_config.xmlattributeActionForm?
 * /*from www.jav  a  2s  .  c  o  m*/
 * @param form
 * @param mapping
 * @param request
 */
public static ActionForm loadActionForm(ActionMapping mapping, HttpServletRequest request) {
    if ("request".equals(mapping.getScope())) {
        return (ActionForm) request.getAttribute(mapping.getAttribute());
    } else {
        HttpSession session = request.getSession();
        return (ActionForm) session.getAttribute(mapping.getAttribute());
    }
}