Example usage for com.liferay.portal.kernel.security.auth AuthTokenUtil getToken

List of usage examples for com.liferay.portal.kernel.security.auth AuthTokenUtil getToken

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.auth AuthTokenUtil getToken.

Prototype

public static String getToken(HttpServletRequest httpServletRequest, long plid, String portletId) 

Source Link

Usage

From source file:com.liferay.asset.publisher.web.portlet.DisplayPageFriendlyURLResolver.java

License:Open Source License

@Override
public String getActualURL(long companyId, long groupId, boolean privateLayout, String mainPath,
        String friendlyURL, Map<String, String[]> params, Map<String, Object> requestContext)
        throws PortalException {

    String urlTitle = friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());

    JournalArticle journalArticle = _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);

    Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL);

    String layoutActualURL = _portal.getLayoutActualURL(layout, mainPath);

    InheritableMap<String, String[]> actualParams = new InheritableMap<>();

    if (params != null) {
        actualParams.setParentMap(params);
    }/*from www.  j ava 2s .  c  om*/

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String defaultAssetPublisherPortletId = typeSettingsProperties
            .get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId;

    if (Validator.isNull(defaultAssetPublisherPortletId)) {
        defaultAssetPublisherPortletId = PortletIdCodec.encode(AssetPublisherPortletKeys.ASSET_PUBLISHER);
    }

    HttpServletRequest request = (HttpServletRequest) requestContext.get("request");

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        String actualPortletAuthenticationToken = AuthTokenUtil.getToken(request, layout.getPlid(),
                defaultAssetPublisherPortletId);

        actualParams.put("p_p_auth", new String[] { actualPortletAuthenticationToken });
    }

    actualParams.put("p_p_id", new String[] { defaultAssetPublisherPortletId });
    actualParams.put("p_p_lifecycle", new String[] { "0" });

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        actualParams.put("p_p_state", new String[] { WindowState.MAXIMIZED.toString() });
    }

    actualParams.put("p_p_mode", new String[] { "view" });
    actualParams.put("p_j_a_id", new String[] { String.valueOf(journalArticle.getId()) });

    String namespace = _portal.getPortletNamespace(defaultAssetPublisherPortletId);

    actualParams.put(namespace + "mvcPath", new String[] { "/view_content.jsp" });

    AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
            .getAssetRendererFactoryByClassName(JournalArticle.class.getName());

    actualParams.put(namespace + "type", new String[] { assetRendererFactory.getType() });

    actualParams.put(namespace + "urlTitle", new String[] { journalArticle.getUrlTitle() });

    String queryString = _http.parameterMapToString(actualParams, false);

    if (layoutActualURL.contains(StringPool.QUESTION)) {
        layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString;
    } else {
        layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString;
    }

    Locale locale = _portal.getLocale(request);

    _portal.addPageSubtitle(journalArticle.getTitle(locale), request);
    _portal.addPageDescription(journalArticle.getDescription(locale), request);

    List<AssetTag> assetTags = _assetTagLocalService.getTags(JournalArticle.class.getName(),
            journalArticle.getPrimaryKey());

    if (!assetTags.isEmpty()) {
        _portal.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
    }

    return layoutActualURL;
}

From source file:com.liferay.dynamic.data.mapping.internal.render.DDMFormFieldFreeMarkerRenderer.java

License:Open Source License

protected Map<String, Object> getFreeMarkerContext(HttpServletRequest request, HttpServletResponse response,
        String portletNamespace, String namespace, DDMFormField ddmFormField, DDMFormField parentDDMFormField,
        boolean showEmptyFieldLabel, Locale locale) {

    Map<String, Object> freeMarkerContext = new HashMap<>();

    Map<String, Object> fieldContext = getFieldContext(request, response, portletNamespace, namespace,
            ddmFormField, locale);/*from  ww w.  ja  v  a  2  s  .  co  m*/

    Map<String, Object> parentFieldContext = new HashMap<>();

    if (parentDDMFormField != null) {
        parentFieldContext = getFieldContext(request, response, portletNamespace, namespace, parentDDMFormField,
                locale);
    }

    freeMarkerContext.put("ddmPortletId", DDMPortletKeys.DYNAMIC_DATA_MAPPING);

    Editor editor = DDMFormFieldFreeMarkerRendererHelper.getEditor(request);

    freeMarkerContext.put("editorName", editor.getName());

    freeMarkerContext.put("fieldStructure", fieldContext);

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

    try {
        String itemSelectorAuthToken = AuthTokenUtil.getToken(request,
                PortalUtil.getControlPanelPlid(themeDisplay.getCompanyId()), PortletKeys.ITEM_SELECTOR);

        freeMarkerContext.put("itemSelectorAuthToken", itemSelectorAuthToken);
    } catch (PortalException pe) {
        _log.error("Unable to generate item selector auth token ", pe);
    }

    freeMarkerContext.put("namespace", namespace);
    freeMarkerContext.put("parentFieldStructure", parentFieldContext);
    freeMarkerContext.put("portletNamespace", portletNamespace);
    freeMarkerContext.put("requestedLanguageDir", LanguageUtil.get(locale, LanguageConstants.KEY_DIR));
    freeMarkerContext.put("requestedLocale", locale);
    freeMarkerContext.put("showEmptyFieldLabel", showEmptyFieldLabel);

    return freeMarkerContext;
}