Example usage for com.liferay.portal.kernel.util CookieKeys getCookie

List of usage examples for com.liferay.portal.kernel.util CookieKeys getCookie

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util CookieKeys getCookie.

Prototype

public static String getCookie(HttpServletRequest httpServletRequest, String name) 

Source Link

Usage

From source file:com.liferay.anonymoususers.util.DefaultAnonymousUsersCookieManagerImpl.java

License:Open Source License

@Override
public long getAnonymousUserId(HttpServletRequest request) {
    return GetterUtil.getLong(CookieKeys.getCookie(request, ANONYMOUS_USER_ID));
}

From source file:com.liferay.contenttargeting.util.CTCookieUtil.java

License:Open Source License

public static long getCTUserId(HttpServletRequest request) {
    return GetterUtil.getLong(CookieKeys.getCookie(request, CT_USER_ID));
}

From source file:com.liferay.opensocial.shindig.servlet.ShindigFilter.java

License:Open Source License

protected boolean setPermissionChecker(ServletRequest servletRequest) {
    String companyIdString = CookieKeys.getCookie((HttpServletRequest) servletRequest, CookieKeys.COMPANY_ID);

    if (Validator.isNull(companyIdString)) {
        return false;
    }// w  w  w .  jav  a 2s . co m

    long companyId = GetterUtil.getLong(companyIdString);

    String userUUID = StringPool.BLANK;

    try {
        Company company = CompanyLocalServiceUtil.fetchCompany(companyId);

        if (company == null) {
            return false;
        }

        String userUUIDString = CookieKeys.getCookie((HttpServletRequest) servletRequest, CookieKeys.USER_UUID);

        if (Validator.isNull(userUUIDString)) {
            return false;
        }

        userUUID = GetterUtil.getString(Encryptor.decrypt(company.getKeyObj(), userUUIDString));
    } catch (EncryptorException ee) {
        return false;
    } catch (Exception e) {
        _log.error(e, e);

        return false;
    }

    if (!AuthenticatedUserUUIDStoreUtil.exists(userUUID)) {
        return false;
    }

    String userIdString = userUUID.substring(0, userUUID.indexOf(StringPool.PERIOD));

    long userId = GetterUtil.getLong(userIdString);

    try {
        User user = UserLocalServiceUtil.getUserById(userId);

        PrincipalThreadLocal.setName(userIdString);

        PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

        PermissionThreadLocal.setPermissionChecker(permissionChecker);
    } catch (Exception e) {
        _log.error(e, e);

        return false;
    }

    return true;
}

From source file:com.liferay.polls.util.PollsUtil.java

License:Open Source License

public static boolean hasVoted(HttpServletRequest request, long pollsQuestionId)
        throws PortalException, SystemException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (themeDisplay.isSignedIn()) {
        try {//from   ww w.  j a v  a2s .  c  om
            PollsVoteLocalServiceUtil.getPollsVote(pollsQuestionId, themeDisplay.getUserId());
        } catch (NoSuchVoteException nsve) {
            return false;
        }

        return true;
    }

    String cookie = CookieKeys.getCookie(request, _getCookieName(pollsQuestionId));

    return GetterUtil.getBoolean(cookie);
}

From source file:com.liferay.polls.web.internal.portlet.util.PollsUtil.java

License:Open Source License

public static boolean hasVoted(HttpServletRequest request, long questionId) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (themeDisplay.isSignedIn()) {
        PollsVote vote = PollsVoteLocalServiceUtil.fetchQuestionUserVote(questionId, themeDisplay.getUserId());

        if (vote == null) {
            return false;
        }// ww w.jav a 2 s .com

        return true;
    }

    String cookie = CookieKeys.getCookie(request, _getCookieName(questionId));

    return GetterUtil.getBoolean(cookie);
}

From source file:com.liferay.wsrp.axis.WSRPHTTPSender.java

License:Open Source License

protected void addForwardCookies(MessageContext messageContext, HttpServletRequest request) {

    if (_forwardCookies.length == 0) {
        return;//from   w ww  .  ja va  2  s  .c om
    }

    Map<String, String> cookiesMap = new HashMap<String, String>();

    Object cookiesObject = messageContext.getProperty(HTTPConstants.HEADER_COOKIE);

    String[] cookies = new String[0];

    if (cookiesObject instanceof String[]) {
        cookies = (String[]) cookiesObject;
    } else if (cookiesObject instanceof String) {
        cookies = new String[] { (String) cookiesObject };
    }

    for (String cookie : cookies) {
        String name = cookie.substring(0, cookie.indexOf(StringPool.EQUAL));

        cookiesMap.put(StringUtil.toLowerCase(name), cookie);
    }

    for (String forwardCookie : _forwardCookies) {
        String value = CookieKeys.getCookie(request, forwardCookie);

        if (Validator.isNull(value)) {
            continue;
        }

        cookiesMap.put(forwardCookie, forwardCookie.concat(StringPool.EQUAL).concat(value));
    }

    Collection<String> cookiesCollection = cookiesMap.values();

    cookiesObject = cookiesCollection.toArray(new String[0]);

    messageContext.setProperty(HTTPConstants.HEADER_COOKIE, cookiesObject);
}