@Override
  public AssetEntry getAssetEntry(String className, long classPK)
      throws PortalException, SystemException {

    LayoutRevision layoutRevision = LayoutRevisionLocalServiceUtil.getLayoutRevision(classPK);

    LayoutSetBranch layoutSetBranch =
        LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(layoutRevision.getLayoutSetBranchId());

    User user = UserLocalServiceUtil.getUserById(layoutRevision.getUserId());

    AssetEntry assetEntry = AssetEntryLocalServiceUtil.createAssetEntry(classPK);

    assetEntry.setGroupId(layoutRevision.getGroupId());
    assetEntry.setCompanyId(user.getCompanyId());
    assetEntry.setUserId(user.getUserId());
    assetEntry.setUserName(user.getFullName());
    assetEntry.setCreateDate(layoutRevision.getCreateDate());
    assetEntry.setClassNameId(PortalUtil.getClassNameId(LayoutRevision.class.getName()));
    assetEntry.setClassPK(layoutRevision.getLayoutRevisionId());

    StringBundler sb = new StringBundler(4);

    sb.append(layoutRevision.getHTMLTitle(LocaleUtil.getSiteDefault()));
    sb.append(" [");
    sb.append(layoutSetBranch.getName());
    sb.append("]");

    assetEntry.setTitle(sb.toString());

    return assetEntry;
  }
Beispiel #2
0
  /** @deprecated As of 6.2.0, replaced by {@link #getUserName(long, ServiceContext)} */
  protected String getUserName(long userId, ThemeDisplay themeDisplay) {
    try {
      if (userId <= 0) {
        return StringPool.BLANK;
      }

      User user = UserLocalServiceUtil.getUserById(userId);

      if (user.getUserId() == themeDisplay.getUserId()) {
        return HtmlUtil.escape(user.getFirstName());
      }

      String userName = user.getFullName();

      Group group = user.getGroup();

      if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
        return HtmlUtil.escape(userName);
      }

      String userDisplayURL = user.getDisplayURL(themeDisplay);

      userName =
          "******"user\" href=\"" + userDisplayURL + "\">" + HtmlUtil.escape(userName) + "</a>";

      return userName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
  public AssetRenderer getAssetRenderer(long classPK, int type)
      throws PortalException, SystemException {

    User user = UserLocalServiceUtil.getUserById(classPK);

    return new UserAssetRenderer(user);
  }
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);
    String receiverUserName = getUserName(activity.getReceiverUserId(), themeDisplay);

    User receiverUser = UserLocalServiceUtil.getUserById(activity.getReceiverUserId());

    if (!SocialRelationLocalServiceUtil.hasRelation(
            themeDisplay.getUserId(),
            activity.getReceiverUserId(),
            SocialRelationConstants.TYPE_BI_FRIEND)
        && (themeDisplay.getUserId() != activity.getReceiverUserId())) {

      return null;
    }

    int activityType = activity.getType();

    // Link

    WallEntry wallEntry = WallEntryLocalServiceUtil.getWallEntry(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathFriendlyURLPublic()
            + StringPool.SLASH
            + HtmlUtil.escapeURL(receiverUser.getScreenName())
            + "/profile/-/wall/"
            + activity.getClassPK();

    // Title

    String title = StringPool.BLANK;

    if (activityType == WallActivityKeys.ADD_ENTRY) {
      title =
          themeDisplay.translate(
              "activity-social-networking-wall-add-entry",
              new Object[] {creatorUserName, receiverUserName});
    }

    // Body

    StringBuilder sb = new StringBuilder();

    sb.append("<a href=\"");
    sb.append(link);
    sb.append("\">");
    sb.append(HtmlUtil.escape(cleanContent(wallEntry.getComments())));
    sb.append("</a>");

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
  }
  public static boolean isOmniadmin(long userId) {
    if (CompanyThreadLocal.getCompanyId() != PortalInstances.getDefaultCompanyId()) {

      return false;
    }

    if (userId <= 0) {
      return false;
    }

    try {
      if (PropsValues.OMNIADMIN_USERS.length > 0) {
        for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
          if (PropsValues.OMNIADMIN_USERS[i] == userId) {
            User user = UserLocalServiceUtil.getUserById(userId);

            if (user.getCompanyId() != PortalInstances.getDefaultCompanyId()) {

              return false;
            }

            return true;
          }
        }

        return false;
      } else {
        User user = UserLocalServiceUtil.getUserById(userId);

        if (user.getCompanyId() != PortalInstances.getDefaultCompanyId()) {

          return false;
        }

        return RoleLocalServiceUtil.hasUserRole(
            userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR, true);
      }
    } catch (Exception e) {
      _log.error(e);

      return false;
    }
  }
  @Override
  public String getStatusByUserUuid() throws SystemException {
    try {
      User user = UserLocalServiceUtil.getUserById(getStatusByUserId());

      return user.getUuid();
    } catch (PortalException pe) {
      return StringPool.BLANK;
    }
  }
  @Override
  public String getReceiverUserUuid() {
    try {
      User user = UserLocalServiceUtil.getUserById(getReceiverUserId());

      return user.getUuid();
    } catch (PortalException pe) {
      return StringPool.BLANK;
    }
  }
Beispiel #8
0
  public void deleteEmailAddress(long companyId, long userId) {
    try {
      User user = UserLocalServiceUtil.getUserById(userId);

      String nickname = _getNickname(user.getEmailAddress());

      GNicknameManager gNicknameManager = GoogleAppsFactoryUtil.getGNicknameManager(companyId);

      gNicknameManager.deleteGNickname(nickname);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  protected ThemeDisplay getThemeDisplay(SecurityToken securityToken) throws Exception {

    long userIdLong = GetterUtil.getLong(securityToken.getViewerId());

    User user = UserLocalServiceUtil.getUserById(userIdLong);

    Company company = CompanyLocalServiceUtil.getCompanyById(user.getCompanyId());

    ThemeDisplay themeDisplay = new ThemeDisplay();

    themeDisplay.setCompany(company);
    themeDisplay.setLocale(user.getLocale());
    themeDisplay.setUser(user);

    return themeDisplay;
  }
Beispiel #10
0
  public void updateEmailAddress(long companyId, long userId, String emailAddress) {

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

      deleteEmailAddress(companyId, userId);

      GNicknameManager gNicknameManager = GoogleAppsFactoryUtil.getGNicknameManager(companyId);

      gNicknameManager.addGNickname(userId, emailAddress);

      GEmailSettingsManager gEmailSettingsManager =
          GoogleAppsFactoryUtil.getGEmailSettingsManager(companyId);

      gEmailSettingsManager.addSendAs(userId, user.getFullName(), emailAddress);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
Beispiel #11
0
  public int doStartTag() throws JspException {
    try {
      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

      request.setAttribute("liferay-ui:user-display:user-id", String.valueOf(_userId));
      request.setAttribute("liferay-ui:user-display:user-name", _userName);

      User user = null;

      try {
        user = UserLocalServiceUtil.getUserById(_userId);

        if (user.isDefaultUser()) {
          user = null;
        }

        request.setAttribute("liferay-ui:user-display:user", user);

        pageContext.setAttribute("userDisplay", user);
      } catch (NoSuchUserException usue) {
        request.removeAttribute("liferay-ui:user-display:user");

        pageContext.removeAttribute("userDisplay");
      }

      request.setAttribute("liferay-ui:user-display:url", _url);
      request.setAttribute("liferay-ui:user-display:displayStyle", String.valueOf(_displayStyle));

      PortalIncludeUtil.include(pageContext, getStartPage());

      if (user != null) {
        return EVAL_BODY_INCLUDE;
      } else {
        return SKIP_BODY;
      }
    } catch (Exception e) {
      throw new JspException(e);
    }
  }
Beispiel #12
0
  protected long loginUser(
      HttpServletRequest request,
      HttpServletResponse response,
      long companyId,
      long userId,
      String remoteUser)
      throws PortalException, SystemException {

    if ((userId > 0) || (remoteUser == null)) {
      return userId;
    }

    if (PropsValues.PORTAL_JAAS_ENABLE) {
      userId = JAASHelper.getJaasUserId(companyId, remoteUser);
    } else {
      userId = GetterUtil.getLong(remoteUser);
    }

    EventsProcessorUtil.process(
        PropsKeys.LOGIN_EVENTS_PRE, PropsValues.LOGIN_EVENTS_PRE, request, response);

    User user = UserLocalServiceUtil.getUserById(userId);

    if (PropsValues.USERS_UPDATE_LAST_LOGIN) {
      UserLocalServiceUtil.updateLastLogin(userId, request.getRemoteAddr());
    }

    HttpSession session = request.getSession();

    session.setAttribute(WebKeys.USER, user);
    session.setAttribute(WebKeys.USER_ID, new Long(userId));
    session.setAttribute(Globals.LOCALE_KEY, user.getLocale());

    EventsProcessorUtil.process(
        PropsKeys.LOGIN_EVENTS_POST, PropsValues.LOGIN_EVENTS_POST, request, response);

    return userId;
  }
Beispiel #13
0
  @Override
  protected void doReindex(String className, long classPK) throws Exception {
    User user = UserLocalServiceUtil.getUserById(classPK);

    doReindex(user);
  }
Beispiel #14
0
  public static void login(
      HttpServletRequest request,
      HttpServletResponse response,
      String login,
      String password,
      boolean rememberMe,
      String authType)
      throws Exception {

    CookieKeys.validateSupportCookie(request);

    HttpSession session = request.getSession();

    Company company = PortalUtil.getCompany(request);

    long userId = getAuthenticatedUserId(request, login, password, authType);

    if (!PropsValues.AUTH_SIMULTANEOUS_LOGINS) {
      Map<String, UserTracker> sessionUsers = LiveUsers.getSessionUsers(company.getCompanyId());

      List<UserTracker> userTrackers = new ArrayList<UserTracker>(sessionUsers.values());

      for (UserTracker userTracker : userTrackers) {
        if (userId == userTracker.getUserId()) {
          HttpSession userTrackerSession = PortalSessionContext.get(userTracker.getSessionId());

          if (userTrackerSession != null) {
            userTrackerSession.invalidate();
          }
        }
      }
    }

    if (PropsValues.SESSION_ENABLE_PHISHING_PROTECTION) {

      // Invalidate the previous session to prevent phishing

      String[] protectedAttributeNames = PropsValues.SESSION_PHISHING_PROTECTED_ATTRIBUTES;

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

      for (String protectedAttributeName : protectedAttributeNames) {
        Object protectedAttributeValue = session.getAttribute(protectedAttributeName);

        if (protectedAttributeValue == null) {
          continue;
        }

        protectedAttributes.put(protectedAttributeName, protectedAttributeValue);
      }

      try {
        session.invalidate();
      } catch (IllegalStateException ise) {

        // This only happens in Geronimo

        if (_log.isWarnEnabled()) {
          _log.warn(ise.getMessage());
        }
      }

      session = request.getSession(true);

      for (String protectedAttributeName : protectedAttributeNames) {
        Object protectedAttributeValue = protectedAttributes.get(protectedAttributeName);

        if (protectedAttributeValue == null) {
          continue;
        }

        session.setAttribute(protectedAttributeName, protectedAttributeValue);
      }
    }

    // Set cookies

    String domain = CookieKeys.getDomain(request);

    User user = UserLocalServiceUtil.getUserById(userId);

    String userIdString = String.valueOf(userId);

    session.setAttribute("j_username", userIdString);
    session.setAttribute("j_password", user.getPassword());
    session.setAttribute("j_remoteuser", userIdString);

    if (PropsValues.SESSION_STORE_PASSWORD) {
      session.setAttribute(WebKeys.USER_PASSWORD, password);
    }

    Cookie companyIdCookie =
        new Cookie(CookieKeys.COMPANY_ID, String.valueOf(company.getCompanyId()));

    if (Validator.isNotNull(domain)) {
      companyIdCookie.setDomain(domain);
    }

    companyIdCookie.setPath(StringPool.SLASH);

    Cookie idCookie =
        new Cookie(CookieKeys.ID, Encryptor.encrypt(company.getKeyObj(), userIdString));

    if (Validator.isNotNull(domain)) {
      idCookie.setDomain(domain);
    }

    idCookie.setPath(StringPool.SLASH);

    Cookie passwordCookie =
        new Cookie(CookieKeys.PASSWORD, Encryptor.encrypt(company.getKeyObj(), password));

    if (Validator.isNotNull(domain)) {
      passwordCookie.setDomain(domain);
    }

    passwordCookie.setPath(StringPool.SLASH);

    Cookie rememberMeCookie = new Cookie(CookieKeys.REMEMBER_ME, Boolean.TRUE.toString());

    if (Validator.isNotNull(domain)) {
      rememberMeCookie.setDomain(domain);
    }

    rememberMeCookie.setPath(StringPool.SLASH);

    int loginMaxAge = PropsValues.COMPANY_SECURITY_AUTO_LOGIN_MAX_AGE;

    if (PropsValues.SESSION_DISABLED) {
      rememberMe = true;
    }

    if (rememberMe) {
      companyIdCookie.setMaxAge(loginMaxAge);
      idCookie.setMaxAge(loginMaxAge);
      passwordCookie.setMaxAge(loginMaxAge);
      rememberMeCookie.setMaxAge(loginMaxAge);
    } else {

      // This was explicitly changed from 0 to -1 so that the cookie lasts
      // as long as the browser. This allows an external servlet wrapped
      // in AutoLoginFilter to work throughout the client connection. The
      // cookies ARE removed on an actual logout, so there is no security
      // issue. See LEP-4678 and LEP-5177.

      companyIdCookie.setMaxAge(-1);
      idCookie.setMaxAge(-1);
      passwordCookie.setMaxAge(-1);
      rememberMeCookie.setMaxAge(0);
    }

    Cookie loginCookie = new Cookie(CookieKeys.LOGIN, login);

    if (Validator.isNotNull(domain)) {
      loginCookie.setDomain(domain);
    }

    loginCookie.setMaxAge(loginMaxAge);
    loginCookie.setPath(StringPool.SLASH);

    Cookie screenNameCookie =
        new Cookie(
            CookieKeys.SCREEN_NAME, Encryptor.encrypt(company.getKeyObj(), user.getScreenName()));

    if (Validator.isNotNull(domain)) {
      screenNameCookie.setDomain(domain);
    }

    screenNameCookie.setMaxAge(loginMaxAge);
    screenNameCookie.setPath(StringPool.SLASH);

    boolean secure = request.isSecure();

    if (secure) {
      Boolean httpsInitial = (Boolean) session.getAttribute(WebKeys.HTTPS_INITIAL);

      if ((httpsInitial == null) || !httpsInitial.booleanValue()) {
        secure = false;
      }
    }

    CookieKeys.addCookie(request, response, companyIdCookie, secure);
    CookieKeys.addCookie(request, response, idCookie, secure);

    if (rememberMe) {
      CookieKeys.addCookie(request, response, passwordCookie, secure);
      CookieKeys.addCookie(request, response, rememberMeCookie, secure);
      CookieKeys.addCookie(request, response, loginCookie, secure);
      CookieKeys.addCookie(request, response, screenNameCookie, secure);
    }
  }
  @Override
  public boolean contains(
      PermissionChecker permissionChecker, long userId, long[] organizationIds, String actionId) {

    if ((actionId.equals(ActionKeys.DELETE)
            || actionId.equals(ActionKeys.IMPERSONATE)
            || actionId.equals(ActionKeys.PERMISSIONS)
            || actionId.equals(ActionKeys.UPDATE))
        && PortalUtil.isOmniadmin(userId)
        && !permissionChecker.isOmniadmin()) {

      return false;
    }

    try {
      User user = null;

      if (userId != ResourceConstants.PRIMKEY_DNE) {
        user = UserLocalServiceUtil.getUserById(userId);

        Contact contact = user.getContact();

        if (permissionChecker.hasOwnerPermission(
                permissionChecker.getCompanyId(),
                User.class.getName(),
                userId,
                contact.getUserId(),
                actionId)
            || (permissionChecker.getUserId() == userId)) {

          return true;
        }
      }

      if (permissionChecker.hasPermission(0, User.class.getName(), userId, actionId)) {

        return true;
      }

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

      if (organizationIds == null) {
        organizationIds = user.getOrganizationIds();
      }

      for (long organizationId : organizationIds) {
        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        if (OrganizationPermissionUtil.contains(
            permissionChecker, organization, ActionKeys.MANAGE_USERS)) {

          if (permissionChecker.getUserId() == user.getUserId()) {
            return true;
          }

          Group organizationGroup = organization.getGroup();

          // Organization administrators can only manage normal users.
          // Owners can only manage normal users and administrators.

          if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
              user.getUserId(),
              organizationGroup.getGroupId(),
              RoleConstants.ORGANIZATION_OWNER,
              true)) {

            continue;
          } else if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                  user.getUserId(),
                  organizationGroup.getGroupId(),
                  RoleConstants.ORGANIZATION_ADMINISTRATOR,
                  true)
              && !UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                  permissionChecker.getUserId(),
                  organizationGroup.getGroupId(),
                  RoleConstants.ORGANIZATION_OWNER,
                  true)) {

            continue;
          }

          return true;
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
  public TasksEntry addTasksEntry(
      long userId,
      String title,
      int priority,
      long assigneeUserId,
      int dueDateMonth,
      int dueDateDay,
      int dueDateYear,
      int dueDateHour,
      int dueDateMinute,
      boolean neverDue,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tasks entry

    User user = UserLocalServiceUtil.getUserById(userId);
    long groupId = serviceContext.getScopeGroupId();
    Date now = new Date();

    Date dueDate = null;

    if (!neverDue) {
      dueDate =
          PortalUtil.getDate(
              dueDateMonth,
              dueDateDay,
              dueDateYear,
              dueDateHour,
              dueDateMinute,
              user.getTimeZone(),
              new TasksEntryDueDateException());
    }

    long tasksEntryId = CounterLocalServiceUtil.increment();

    TasksEntry tasksEntry = tasksEntryPersistence.create(tasksEntryId);

    tasksEntry.setGroupId(groupId);
    tasksEntry.setCompanyId(user.getCompanyId());
    tasksEntry.setUserId(user.getUserId());
    tasksEntry.setUserName(user.getFullName());
    tasksEntry.setCreateDate(now);
    tasksEntry.setModifiedDate(now);
    tasksEntry.setTitle(title);
    tasksEntry.setPriority(priority);
    tasksEntry.setAssigneeUserId(assigneeUserId);
    tasksEntry.setDueDate(dueDate);
    tasksEntry.setStatus(TasksEntryConstants.STATUS_OPEN);

    tasksEntryPersistence.update(tasksEntry, false);

    // Asset

    updateAsset(
        userId,
        tasksEntry,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    // Social

    SocialActivityLocalServiceUtil.addActivity(
        userId,
        groupId,
        TasksEntry.class.getName(),
        tasksEntryId,
        TasksActivityKeys.ADD_ENTRY,
        StringPool.BLANK,
        assigneeUserId);

    return tasksEntry;
  }
  public TasksEntry updateTasksEntry(
      long tasksEntryId,
      String title,
      int priority,
      long assigneeUserId,
      long resolverUserId,
      int dueDateMonth,
      int dueDateDay,
      int dueDateYear,
      int dueDateHour,
      int dueDateMinute,
      boolean neverDue,
      int status,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tasks entry

    Date now = new Date();

    TasksEntry tasksEntry = tasksEntryPersistence.findByPrimaryKey(tasksEntryId);

    User user = UserLocalServiceUtil.getUserById(tasksEntry.getUserId());

    Date dueDate = null;

    if (!neverDue) {
      dueDate =
          PortalUtil.getDate(
              dueDateMonth,
              dueDateDay,
              dueDateYear,
              dueDateHour,
              dueDateMinute,
              user.getTimeZone(),
              new TasksEntryDueDateException());
    }

    tasksEntry.setModifiedDate(now);
    tasksEntry.setTitle(title);
    tasksEntry.setPriority(priority);
    tasksEntry.setAssigneeUserId(assigneeUserId);
    tasksEntry.setDueDate(dueDate);

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      tasksEntry.setResolverUserId(resolverUserId);
      tasksEntry.setFinishDate(now);
    } else {
      tasksEntry.setResolverUserId(0);
      tasksEntry.setFinishDate(null);
    }

    tasksEntry.setStatus(status);

    tasksEntryPersistence.update(tasksEntry, false);

    // Asset

    updateAsset(
        tasksEntry.getUserId(),
        tasksEntry,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    // Social

    int activity = TasksActivityKeys.UPDATE_ENTRY;

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      activity = TasksActivityKeys.RESOLVE_ENTRY;
    } else if (status == TasksEntryConstants.STATUS_REOPENED) {
      activity = TasksActivityKeys.REOPEN_ENTRY;
    }

    SocialActivityLocalServiceUtil.addActivity(
        serviceContext.getUserId(),
        tasksEntry.getGroupId(),
        TasksEntry.class.getName(),
        tasksEntryId,
        activity,
        StringPool.BLANK,
        assigneeUserId);

    return tasksEntry;
  }
  @Override
  public boolean contains(PermissionChecker permissionChecker, Group group, String actionId)
      throws PortalException, SystemException {

    long groupId = group.getGroupId();

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    if (group.isUser()) {

      // An individual user would never reach this block because he would
      // be an administrator of his own layouts. However, a user who
      // manages a set of organizations may be modifying pages of a user
      // he manages.

      User user = UserLocalServiceUtil.getUserById(group.getClassPK());

      if ((permissionChecker.getUserId() != user.getUserId())
          && UserPermissionUtil.contains(
              permissionChecker, user.getUserId(), user.getOrganizationIds(), ActionKeys.UPDATE)) {

        return true;
      }
    }

    if (actionId.equals(ActionKeys.ADD_COMMUNITY)
            && permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_SUBGROUPS)
        || PortalPermissionUtil.contains(permissionChecker, ActionKeys.ADD_COMMUNITY)) {

      return true;
    } else if (actionId.equals(ActionKeys.ADD_LAYOUT)
        && !group.isLayoutPrototype()
        && permissionChecker.hasPermission(
            groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS)) {

      return true;
    } else if ((actionId.equals(ActionKeys.EXPORT_IMPORT_LAYOUTS)
            || actionId.equals(ActionKeys.EXPORT_IMPORT_PORTLET_INFO))
        && permissionChecker.hasPermission(
            groupId, Group.class.getName(), groupId, ActionKeys.PUBLISH_STAGING)) {

      return true;
    } else if (actionId.equals(ActionKeys.VIEW)
        && (permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.ASSIGN_USER_ROLES)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS))) {

      return true;
    } else if (actionId.equals(ActionKeys.VIEW_STAGING)
        && (permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_STAGING)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.PUBLISH_STAGING)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.UPDATE))) {

      return true;
    }

    // Group id must be set so that users can modify their personal pages

    if (permissionChecker.hasPermission(groupId, Group.class.getName(), groupId, actionId)) {

      return true;
    }

    while (!group.isRoot()) {
      if (contains(permissionChecker, group.getParentGroupId(), ActionKeys.MANAGE_SUBGROUPS)) {

        return true;
      }

      group = group.getParentGroup();
    }

    return false;
  }
Beispiel #19
0
  public Orange(HashMap values) {

    super(values);
    this.setDoctype(Global.ORANGE);

    if (values.containsKey("uid")) {
      this.setId((String) values.get("uid"));
    }
    if (values.containsKey("PID")) {
      this.setPid((String) values.get("PID"));
    }
    if (values.containsKey("mods.title")) {
      this.setModsTitle((String) values.get("mods.title"));
    }
    if (values.containsKey("mods.author")) {
      this.setModsAuthor((String) values.get("mods.author"));
    }
    if (values.containsKey("mods.host.title")) {
      this.setModsHostTitle((String) values.get("mods.host.title"));
    }
    if (values.containsKey("mods.publication.date")) {
      this.setModsPublicationDate((String) values.get("mods.publication.date"));
    }
    if (values.containsKey("mods.ext.volume")) {
      this.setModsExtVolume((String) values.get("mods.ext.volume"));
    }
    if (values.containsKey("mods.ext.part")) {
      this.setModsExtPart((String) values.get("mods.ext.part"));
    }
    if (values.containsKey("mods.ext.pages")) {
      this.setModsExtPages((String) values.get("mods.ext.pages"));
    }

    if (values.containsKey("mods.host.author")) {
      this.setModsHostAuthor((String) values.get("mods.host.author"));
    }

    if (values.containsKey("mods.publisher")) {
      this.setModsPublisher((String) values.get("mods.publisher"));
    }

    if (values.containsKey("mods.publisher.location")) {
      this.setModsPublisherLocation((String) values.get("mods.publisher.location"));
    }

    if (values.containsKey("mods.shelfmark")) {
      this.setModsShelfmark((String) values.get("mods.shelfmark"));
    }

    if (values.containsKey("mods.reviewer.roleTerm")) {
      this.setReviewerRoleterm((String) values.get("mods.reviewer.roleTerm"));
    }

    if (values.containsKey("lastModifiedDate")) {
      String date = (String) values.get("lastModifiedDate");
      String day = date.substring(0, 10);
      String time = date.substring(11, 23);
      String formattedDate = day + "</br>" + time;
      this.setLastModifiedDate(formattedDate);
    }

    if (values.containsKey("roleIds")) {
      // parse to remove administrator
      String[] roleIds = ((String) values.get("roleIds")).split(",");
      String roleId = "";
      for (String thisRole : roleIds) {
        if (!thisRole.equals("administrator")) {
          roleId = thisRole.replaceAll("[^0-9]", "");
        }
      }
      User user;
      try {
        user = UserLocalServiceUtil.getUserById(Integer.parseInt(roleId));
        this.setUploader(user.getFullName());
        this.setUploaderScreenName(user.getScreenName());

      } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (PortalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    this.setStatus("Dataset is in the Orange Category");
    this.setStatusImgURL("/resources/images/orange.png");
    this.setMakeDatasetPublicText("Make Dataset publicly available");

    this.setDatasetdisplayURL(formatDatasetDisplayURL());
  }
  public boolean containsWithoutViewableGroup(
      PermissionChecker permissionChecker,
      Layout layout,
      String controlPanelCategory,
      boolean checkLayoutUpdateable,
      String actionId)
      throws PortalException, SystemException {

    if (checkLayoutUpdateable
        && !actionId.equals(ActionKeys.CUSTOMIZE)
        && !actionId.equals(ActionKeys.VIEW)
        && (layout instanceof VirtualLayout)) {

      return false;
    }

    if (actionId.equals(ActionKeys.CUSTOMIZE) && (layout instanceof VirtualLayout)) {

      VirtualLayout virtualLayout = (VirtualLayout) layout;

      layout = virtualLayout.getWrappedModel();
    }

    if (actionId.equals(ActionKeys.DELETE) && !SitesUtil.isLayoutDeleteable(layout)) {

      return false;
    }

    Group group = layout.getGroup();

    if (checkLayoutUpdateable
        && !group.isLayoutSetPrototype()
        && isAttemptToModifyLockedLayout(layout, actionId)) {

      return false;
    }

    User user = UserLocalServiceUtil.getUserById(permissionChecker.getUserId());

    if ((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6)
        && !user.isDefaultUser()
        && !group.isUser()) {

      // This is new way of doing an ownership check without having to
      // have a userId field on the model. When the instance model was
      // first created, we set the user's userId as the ownerId of the
      // individual scope ResourcePermission of the Owner Role.
      // Therefore, ownership can be determined by obtaining the Owner
      // role ResourcePermission for the current instance model and
      // testing it with the hasOwnerPermission call.

      ResourcePermission resourcePermission =
          ResourcePermissionLocalServiceUtil.getResourcePermission(
              layout.getCompanyId(),
              Layout.class.getName(),
              ResourceConstants.SCOPE_INDIVIDUAL,
              String.valueOf(layout.getPlid()),
              permissionChecker.getOwnerRoleId());

      if (permissionChecker.hasOwnerPermission(
          layout.getCompanyId(),
          Layout.class.getName(),
          String.valueOf(layout.getPlid()),
          resourcePermission.getOwnerId(),
          actionId)) {

        return true;
      }
    }

    if (GroupPermissionUtil.contains(
        permissionChecker, layout.getGroupId(), ActionKeys.MANAGE_LAYOUTS)) {

      return true;
    } else if (actionId.equals(ActionKeys.ADD_LAYOUT)
        && GroupPermissionUtil.contains(
            permissionChecker, layout.getGroupId(), ActionKeys.ADD_LAYOUT)) {

      return true;
    }

    if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE && !actionId.equals(ActionKeys.VIEW)) {

      // Check upward recursively to see if any pages above grant the
      // action

      long parentLayoutId = layout.getParentLayoutId();

      while (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
        Layout parentLayout =
            LayoutLocalServiceUtil.getLayout(
                layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

        if (contains(permissionChecker, parentLayout, controlPanelCategory, actionId)) {

          return true;
        }

        parentLayoutId = parentLayout.getParentLayoutId();
      }
    }

    try {
      if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
        if (ResourcePermissionLocalServiceUtil.getResourcePermissionsCount(
                layout.getCompanyId(),
                Layout.class.getName(),
                ResourceConstants.SCOPE_INDIVIDUAL,
                String.valueOf(layout.getPlid()))
            == 0) {

          throw new NoSuchResourceException();
        }
      } else {
        ResourceLocalServiceUtil.getResource(
            layout.getCompanyId(),
            Layout.class.getName(),
            ResourceConstants.SCOPE_INDIVIDUAL,
            String.valueOf(layout.getPlid()));
      }
    } catch (NoSuchResourceException nsre) {
      boolean addGroupPermission = true;
      boolean addGuestPermission = true;

      if (layout.isPrivateLayout()) {
        addGuestPermission = false;
      }

      ResourceLocalServiceUtil.addResources(
          layout.getCompanyId(),
          layout.getGroupId(),
          0,
          Layout.class.getName(),
          layout.getPlid(),
          false,
          addGroupPermission,
          addGuestPermission);
    }

    return permissionChecker.hasPermission(
        layout.getGroupId(), Layout.class.getName(), layout.getPlid(), actionId);
  }
  protected boolean isViewableGroup(
      PermissionChecker permissionChecker,
      Layout layout,
      String controlPanelCategory,
      boolean checkResourcePermission)
      throws PortalException, SystemException {

    Group group = GroupLocalServiceUtil.getGroup(layout.getGroupId());

    // Inactive sites are not viewable

    if (!group.isActive()) {
      return false;
    } else if (group.isStagingGroup()) {
      Group liveGroup = group.getLiveGroup();

      if (!liveGroup.isActive()) {
        return false;
      }
    }

    // User private layouts are only viewable by the user and anyone who can
    // update the user. The user must also be active.

    if (group.isUser()) {
      long groupUserId = group.getClassPK();

      if (groupUserId == permissionChecker.getUserId()) {
        return true;
      }

      User groupUser = UserLocalServiceUtil.getUserById(groupUserId);

      if (!groupUser.isActive()) {
        return false;
      }

      if (layout.isPrivateLayout()) {
        if (GroupPermissionUtil.contains(
                permissionChecker, groupUser.getGroupId(), ActionKeys.MANAGE_LAYOUTS)
            || UserPermissionUtil.contains(
                permissionChecker,
                groupUserId,
                groupUser.getOrganizationIds(),
                ActionKeys.UPDATE)) {

          return true;
        }

        return false;
      }
    }

    // If the current group is staging, only users with editorial rights
    // can access it

    if (group.isStagingGroup()) {
      if (GroupPermissionUtil.contains(
          permissionChecker, group.getGroupId(), ActionKeys.VIEW_STAGING)) {

        return true;
      }

      return false;
    }

    // Control panel layouts are only viewable by authenticated users

    if (group.isControlPanel()) {
      if (!permissionChecker.isSignedIn()) {
        return false;
      }

      if (PortalPermissionUtil.contains(permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) {

        return true;
      }

      if (Validator.isNotNull(controlPanelCategory)) {
        return true;
      }

      return false;
    }

    // Site layouts are only viewable by users who are members of the site
    // or by users who can update the site

    if (group.isSite()) {
      if (GroupPermissionUtil.contains(
              permissionChecker, group.getGroupId(), ActionKeys.MANAGE_LAYOUTS)
          || GroupPermissionUtil.contains(
              permissionChecker, group.getGroupId(), ActionKeys.UPDATE)) {

        return true;
      }

      if (layout.isPrivateLayout() && !permissionChecker.isGroupMember(group.getGroupId())) {

        return false;
      }
    }

    // Organization site layouts are also viewable by users who belong to
    // the organization or by users who can update organization

    if (group.isCompany()) {
      return false;
    } else if (group.isLayoutPrototype()) {
      if (LayoutPrototypePermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.VIEW)) {

        return true;
      }

      return false;
    } else if (group.isLayoutSetPrototype()) {
      if (LayoutSetPrototypePermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.VIEW)) {

        return true;
      }

      return false;
    } else if (group.isOrganization()) {
      long organizationId = group.getOrganizationId();

      if (OrganizationLocalServiceUtil.hasUserOrganization(
          permissionChecker.getUserId(), organizationId, false, false)) {

        return true;
      } else if (OrganizationPermissionUtil.contains(
          permissionChecker, organizationId, ActionKeys.UPDATE)) {

        return true;
      }

      if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {
        List<Organization> userOrgs =
            OrganizationLocalServiceUtil.getUserOrganizations(permissionChecker.getUserId());

        for (Organization organization : userOrgs) {
          for (Organization ancestorOrganization : organization.getAncestors()) {

            if (organizationId == ancestorOrganization.getOrganizationId()) {

              return true;
            }
          }
        }
      }
    } else if (group.isUserGroup()) {
      if (UserGroupPermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.UPDATE)) {

        return true;
      }
    }

    // Only check the actual Layout if all of the above failed

    if (containsWithoutViewableGroup(
        permissionChecker, layout, controlPanelCategory, ActionKeys.VIEW)) {

      return true;
    }

    // As a last resort, check if any top level pages are viewable by the
    // user

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            layout.getGroupId(),
            layout.isPrivateLayout(),
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    for (Layout curLayout : layouts) {
      if (!curLayout.isHidden()
          && containsWithoutViewableGroup(
              permissionChecker, curLayout, controlPanelCategory, ActionKeys.VIEW)) {

        return true;
      }
    }

    return false;
  }
Beispiel #22
0
  @Override
  protected void doReindex(Object obj) throws Exception {
    if (obj instanceof Long) {
      long userId = (Long) obj;

      User user = UserLocalServiceUtil.getUserById(userId);

      doReindex(user);
    } else if (obj instanceof long[]) {
      long[] userIds = (long[]) obj;

      Map<Long, Collection<Document>> documentsMap = new HashMap<>();

      for (long userId : userIds) {
        User user = UserLocalServiceUtil.getUserById(userId);

        if (user.isDefaultUser()) {
          continue;
        }

        Document document = getDocument(user);

        long companyId = user.getCompanyId();

        Collection<Document> documents = documentsMap.get(companyId);

        if (documents == null) {
          documents = new ArrayList<>();

          documentsMap.put(companyId, documents);
        }

        documents.add(document);
      }

      for (Map.Entry<Long, Collection<Document>> entry : documentsMap.entrySet()) {

        long companyId = entry.getKey();
        Collection<Document> documents = entry.getValue();

        SearchEngineUtil.updateDocuments(
            getSearchEngineId(), companyId, documents, isCommitImmediately());
      }
    } else if (obj instanceof User) {
      User user = (User) obj;

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

      Document document = getDocument(user);

      SearchEngineUtil.updateDocument(
          getSearchEngineId(), user.getCompanyId(), document, isCommitImmediately());

      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Contact.class);

      try {
        indexer.reindex(user.getContact());
      } catch (NoSuchContactException nscce) {

        // This is a temporary workaround for LPS-46825

      }
    }
  }