protected void updateAccessToken(RenderRequest renderRequest, String oAuthVerifier)
      throws Exception {

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

    Token requestToken = oAuthManager.getRequestToken(themeDisplay.getUser());

    OAuthService oAuthService = oAuthManager.getOAuthService();

    Token accessToken = oAuthService.getAccessToken(requestToken, new Verifier(oAuthVerifier));

    oAuthManager.updateAccessToken(themeDisplay.getUser(), accessToken);

    oAuthManager.deleteRequestToken(themeDisplay.getUser());
  }
  public LinkedHashMap<String, Object> getGroupParams() throws PortalException {

    if (_groupParams != null) {
      return _groupParams;
    }

    long groupId = ParamUtil.getLong(_request, "groupId");
    boolean includeCurrentGroup = ParamUtil.getBoolean(_request, "includeCurrentGroup", true);

    String type = getType();

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
    User user = themeDisplay.getUser();

    boolean filterManageableGroups = true;

    if (permissionChecker.isCompanyAdmin()) {
      filterManageableGroups = false;
    }

    _groupParams = new LinkedHashMap<>();

    _groupParams.put("active", Boolean.TRUE);

    if (isManualMembership()) {
      _groupParams.put("manualMembership", Boolean.TRUE);
    }

    if (type.equals("child-sites")) {
      Group parentGroup = GroupLocalServiceUtil.getGroup(groupId);

      List<Group> parentGroups = new ArrayList<>();

      parentGroups.add(parentGroup);

      _groupParams.put("groupsTree", parentGroups);
    } else if (filterManageableGroups) {
      _groupParams.put("usersGroups", user.getUserId());
    }

    _groupParams.put("site", Boolean.TRUE);

    if (!includeCurrentGroup && (groupId > 0)) {
      List<Long> excludedGroupIds = new ArrayList<>();

      Group group = GroupLocalServiceUtil.getGroup(groupId);

      if (group.isStagingGroup()) {
        excludedGroupIds.add(group.getLiveGroupId());
      } else {
        excludedGroupIds.add(groupId);
      }

      _groupParams.put("excludedGroupIds", excludedGroupIds);
    }

    return _groupParams;
  }
  protected void remoteServeResource(
      ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL());

    setRequestParameters(resourceRequest, resourceResponse, oAuthRequest);

    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "2");
    addOAuthParameter(oAuthRequest, "p_p_resource_id", resourceRequest.getResourceID());

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    String contentType = response.getHeader(HttpHeaders.CONTENT_TYPE);

    if (contentType.startsWith(ContentTypes.APPLICATION_OCTET_STREAM)) {
      String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION);
      int contentLength = GetterUtil.getInteger(response.getHeader(HttpHeaders.CONTENT_LENGTH));

      PortletResponseUtil.sendFile(
          resourceRequest,
          resourceResponse,
          getFileName(contentDisposition),
          response.getStream(),
          contentLength,
          contentType,
          HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT);
    } else {
      PortletResponseUtil.write(resourceResponse, response.getStream());
    }
  }
  protected void remoteProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, getServerPortletURL());

    setRequestParameters(actionRequest, actionResponse, oAuthRequest);

    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "1");
    addOAuthParameter(oAuthRequest, "p_p_state", WindowState.NORMAL.toString());

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    if (response.getCode() == HttpServletResponse.SC_FOUND) {
      String redirectLocation = response.getHeader(HttpHeaders.LOCATION);

      actionResponse.sendRedirect(redirectLocation);
    } else {
      HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);

      httpServletResponse.setContentType(response.getHeader(HttpHeaders.CONTENT_TYPE));

      ServletResponseUtil.write(httpServletResponse, response.getStream());
    }
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    PortletURL portletURL = renderResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "hello_soy_description");

    template.put("descriptionURL", portletURL.toString());

    String path = getPath(renderRequest, renderResponse);

    if (Validator.equals(path, "hello_soy_edit")) {
      portletURL.setParameter("mvcPath", "hello_soy_view");
    } else {
      portletURL.setParameter("mvcPath", "hello_soy_edit");
    }

    template.put("portletURL", portletURL.toString());

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

    User user = themeDisplay.getUser();

    template.put("userName", user.getFirstName());

    super.render(renderRequest, renderResponse);
  }
Beispiel #6
0
  public static ExportImportConfiguration buildDefaultRemotePublishingExportImportConfiguration(
      PortletRequest portletRequest) throws PortalException {

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

    long sourceGroupId = ParamUtil.getLong(portletRequest, "sourceGroupId");
    boolean privateLayout = ParamUtil.getBoolean(portletRequest, "privateLayout");
    String remoteAddress = ParamUtil.getString(portletRequest, "remoteAddress");
    int remotePort = ParamUtil.getInteger(portletRequest, "remotePort");
    String remotePathContext = ParamUtil.getString(portletRequest, "remotePathContext");
    boolean secureConnection = ParamUtil.getBoolean(portletRequest, "secureConnection");
    long remoteGroupId = ParamUtil.getLong(portletRequest, "remoteGroupId");

    Map<String, String[]> parameterMap = getDefaultPublishingParameters(portletRequest);

    return buildDefaultRemotePublishingExportImportConfiguration(
        themeDisplay.getUser(),
        sourceGroupId,
        privateLayout,
        remoteAddress,
        remotePort,
        remotePathContext,
        secureConnection,
        remoteGroupId,
        parameterMap);
  }
  @Override
  public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();

    if (user.isDefaultUser()) {
      return false;
    }

    return true;
  }
Beispiel #8
0
  public static ExportImportConfiguration buildDefaultLocalPublishingExportImportConfiguration(
      PortletRequest portletRequest) throws PortalException {

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

    long sourceGroupId = ParamUtil.getLong(portletRequest, "sourceGroupId");
    long targetGroupId = ParamUtil.getLong(portletRequest, "targetGroupId");
    boolean privateLayout = ParamUtil.getBoolean(portletRequest, "privateLayout");

    Map<String, String[]> parameterMap = getDefaultPublishingParameters(portletRequest);

    return buildDefaultLocalPublishingExportImportConfiguration(
        themeDisplay.getUser(), sourceGroupId, targetGroupId, privateLayout, parameterMap);
  }
  public void deauthorize(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    oAuthManager.deleteAccessToken(themeDisplay.getUser());

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

    PortletURL portletURL = liferayPortletResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "/view.jsp");

    actionResponse.sendRedirect(portletURL.toString());
  }
Beispiel #10
0
  public AssetEntryQuery getAssetEntryQuery() throws Exception {
    if (_assetEntryQuery != null) {
      return _assetEntryQuery;
    }

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

    _assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(
            _portletPreferences, getGroupIds(), getAllAssetCategoryIds(), getAllAssetTagNames());

    String portletName = getPortletName();

    if (!portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) {
      _assetEntryQuery.setGroupIds(getGroupIds());
    }

    _assetEntryQuery.setClassTypeIds(getClassTypeIds());
    _assetEntryQuery.setEnablePermissions(isEnablePermissions());
    _assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());

    configureSubtypeFieldFilter(_assetEntryQuery, themeDisplay.getLocale());

    if (isShowOnlyLayoutAssets()) {
      _assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    if (portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) {
      AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);

      if (layoutAssetEntry != null) {
        _assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
      }
    }

    _assetEntryQuery.setPaginationType(getPaginationType());
    _assetEntryQuery.setOrderByCol1(getOrderByColumn1());
    _assetEntryQuery.setOrderByCol2(getOrderByColumn2());
    _assetEntryQuery.setOrderByType1(getOrderByType1());
    _assetEntryQuery.setOrderByType2(getOrderByType2());

    AssetPublisherUtil.processAssetEntryQuery(
        themeDisplay.getUser(), _portletPreferences, _assetEntryQuery);

    return _assetEntryQuery;
  }
  protected void remoteRender(RenderRequest renderRequest, RenderResponse renderResponse)
      throws Exception {

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL());

    setRequestParameters(renderRequest, renderResponse, oAuthRequest);

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    renderResponse.setContentType(ContentTypes.TEXT_HTML);

    PrintWriter printWriter = renderResponse.getWriter();

    printWriter.write(response.getBody());
  }
  public void authorize(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    OAuthService oAuthService = oAuthManager.getOAuthService();

    Token requestToken = oAuthService.getRequestToken();

    oAuthManager.updateRequestToken(themeDisplay.getUser(), requestToken);

    String redirect = oAuthService.getAuthorizationUrl(requestToken);

    String callbackURL = ParamUtil.getString(actionRequest, "callbackURL");

    redirect = HttpUtil.addParameter(redirect, OAuthConstants.CALLBACK, callbackURL);

    actionResponse.sendRedirect(redirect);
  }
  protected List<Group> getAllGroups(PortletRequest portletRequest) throws PortalException {

    List<Group> groups = new ArrayList<>();

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

    User user = themeDisplay.getUser();

    groups =
        user.getMySiteGroups(
            new String[] {Group.class.getName(), Organization.class.getName()}, QueryUtil.ALL_POS);

    long groupId =
        ParamUtil.getLong(portletRequest, "groupId", GroupConstants.DEFAULT_PARENT_GROUP_ID);

    if (groupId != GroupConstants.DEFAULT_PARENT_GROUP_ID) {
      groups.clear();

      groups.add(_groupLocalService.getGroup(groupId));
    }

    return groups;
  }
  protected LinkedHashMap<String, Object> getGroupParams(
      PortletRequest portletRequest, GroupSearchTerms searchTerms, long parentGroupId)
      throws PortalException {

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

    LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

    groupParams.put("site", Boolean.TRUE);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    User user = themeDisplay.getUser();

    if (searchTerms.hasSearchTerms()) {
      if (isFilterManageableGroups(portletRequest)) {
        groupParams.put("groupsTree", getAllGroups(portletRequest));
      } else if (parentGroupId > 0) {
        List<Group> groupsTree = new ArrayList<>();

        Group parentGroup = _groupLocalService.getGroup(parentGroupId);

        groupsTree.add(parentGroup);

        groupParams.put("groupsTree", groupsTree);
      }

      if (!permissionChecker.isCompanyAdmin()
          && !GroupPermissionUtil.contains(permissionChecker, ActionKeys.VIEW)) {

        groupParams.put("usersGroups", Long.valueOf(user.getUserId()));
      }
    }

    return groupParams;
  }
  @Override
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();

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

    String languageId = ParamUtil.getString(request, "languageId");

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    if (LanguageUtil.isAvailableLocale(themeDisplay.getSiteGroupId(), locale)) {

      boolean persistState = ParamUtil.getBoolean(request, "persistState", true);

      if (themeDisplay.isSignedIn() && persistState) {
        User user = themeDisplay.getUser();

        Contact contact = user.getContact();

        AdminUtil.updateUser(
            request,
            user.getUserId(),
            user.getScreenName(),
            user.getEmailAddress(),
            user.getFacebookId(),
            user.getOpenId(),
            languageId,
            user.getTimeZoneId(),
            user.getGreeting(),
            user.getComments(),
            contact.getSmsSn(),
            contact.getFacebookSn(),
            contact.getJabberSn(),
            contact.getSkypeSn(),
            contact.getTwitterSn());
      }

      session.setAttribute(Globals.LOCALE_KEY, locale);

      LanguageUtil.updateCookie(request, response, locale);
    }

    // Send redirect

    String redirect = ParamUtil.getString(request, "redirect");

    String layoutURL = StringPool.BLANK;
    String queryString = StringPool.BLANK;

    int pos = redirect.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

    if (pos == -1) {
      pos = redirect.indexOf(StringPool.QUESTION);
    }

    if (pos != -1) {
      layoutURL = redirect.substring(0, pos);
      queryString = redirect.substring(pos);
    } else {
      layoutURL = redirect;
    }

    Layout layout = themeDisplay.getLayout();

    if (isGroupFriendlyURL(layout.getGroup(), layout, layoutURL, locale)) {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        redirect = layoutURL;
      } else {
        redirect = PortalUtil.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay, locale);
      }
    } else {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        if (themeDisplay.isI18n()) {
          redirect = layout.getFriendlyURL(locale);
        } else {
          redirect = PortalUtil.getLayoutURL(layout, themeDisplay, locale);
        }
      } else {
        redirect = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay, locale);
      }
    }

    if (layout.isTypeControlPanel()) {
      redirect = redirect + queryString;
    }

    response.sendRedirect(redirect);

    return null;
  }