コード例 #1
0
 /** {@inheritDoc} */
 @Override
 public Serializable execute(final PrincipalActionContext inActionContext) {
   for (SettingsUpdater updater : updaters) {
     updater.update(
         (Map<String, Serializable>) inActionContext.getParams(), inActionContext.getPrincipal());
   }
   return true;
 }
コード例 #2
0
  /**
   * Returns Set of people following a user excluding themselves.
   *
   * @param inActionContext The action context.
   * @return true if the group exists and the user is authorized, false otherwise
   */
  @Override
  public PagedSet<FollowerStatusable> execute(final PrincipalActionContext inActionContext) {
    // get the request
    GetFollowersFollowingRequest inRequest =
        (GetFollowersFollowingRequest) inActionContext.getParams();

    // get the unique entity Id
    final String entityUniqueId = inRequest.getEntityId();

    final long currentUserId = inActionContext.getPrincipal().getId();

    Long entityId = getPersonIdByAccountIdMapper.execute(entityUniqueId);

    List<Long> allIds = idsMapper.execute(entityId);

    // determine the page
    int startIndex = (inRequest.getStartIndex()).intValue();
    int endIndex = (inRequest.getEndIndex()).intValue();

    PagedSet<FollowerStatusable> pagedSet;
    if (allIds.isEmpty()) {
      pagedSet = new PagedSet<FollowerStatusable>();
    } else if (startIndex >= allIds.size()) {
      // if asking for a range beyond the end of the list return an empty set
      pagedSet = new PagedSet<FollowerStatusable>();
      pagedSet.setTotal(allIds.size());
    } else {
      if (endIndex >= allIds.size()) {
        endIndex = allIds.size() - 1;
      }
      List<Long> pageIds = allIds.subList(startIndex, endIndex + 1);

      List<FollowerStatusable> list = bulkModelViewMapper.execute(pageIds);
      followerStatusPopulator.execute(currentUserId, list, FollowerStatus.NOTSPECIFIED);

      pagedSet = new PagedSet<FollowerStatusable>(startIndex, endIndex, allIds.size(), list);
    }

    if (log.isTraceEnabled()) {
      log.trace(
          "Retrieved "
              + pagedSet.getFromIndex()
              + " to "
              + pagedSet.getToIndex()
              + " of "
              + pagedSet.getTotal()
              + " following for person "
              + entityUniqueId);
    }

    return pagedSet;
  }
コード例 #3
0
  /**
   * {@inheritDoc}.
   *
   * <p>This method checks that the accountid of the person making the request matches the accountid
   * passed in by the form specified by the configured key.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void authorize(final PrincipalActionContext inActionContext)
      throws AuthorizationException {
    Map<String, Serializable> inFields = (Map<String, Serializable>) inActionContext.getParams();
    // TODO:This should go in a validation strategy.
    if (!inFields.containsKey(accountIdFieldKey)) {
      throw new AuthorizationException("Account key does not exist, failed to authorize.");
    }

    if (inActionContext
            .getPrincipal()
            .getAccountId()
            .compareToIgnoreCase((String) inFields.get(accountIdFieldKey))
        != 0) {
      throw new AuthorizationException("Insufficient permissions to update personal profile.");
    }
  }
コード例 #4
0
  /**
   * Perform security check on this action to verify user can execute. Throw appropriate
   * AuthorizationException in needed.
   *
   * @param inActionContext {@link PrincipalActionContext}.
   * @throws AuthorizationException thrown if the user does not have proper access
   */
  @Override
  public void authorize(final PrincipalActionContext inActionContext)
      throws AuthorizationException {
    AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams();
    Long tabId = request.getTabId();

    // get the Tab we're inserting the Gadget into
    if (tabId == null) {
      // if client passes null for id, find the first tab
      Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId());
      tabId = person.getStartTabGroup().getTabs().get(0).getId();
    }

    // This will throw AuthorizationException if user doesn't have permissions.
    if (!tabPermission.canModifyGadgets(
        inActionContext.getPrincipal().getAccountId(), tabId, true)) {
      throw new AuthorizationException("Failed to authorize adding of the supplied gadget.");
    }
  }
コード例 #5
0
  /**
   * Delete a bookmark from current user's collection.
   *
   * @param inActionContext action context.
   * @return true upon successful completion.
   */
  @Override
  public Serializable execute(final PrincipalActionContext inActionContext) {
    Person person =
        personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId()));
    Long ssIdToRemove = (Long) inActionContext.getParams();
    List<StreamScope> bookmarks = person.getBookmarks();

    log.debug("Attempting to delete bookmark with id: " + ssIdToRemove);

    for (StreamScope ss : bookmarks) {
      log.debug("Examinging SS with id: " + ss.getId());
      if (ss.getId() == ssIdToRemove) {
        log.debug("Match found!");
        bookmarks.remove(ss);
        personMapper.flush();
        break;
      }
    }

    return Boolean.TRUE;
  }
コード例 #6
0
  @Override
  public Serializable execute(final PrincipalActionContext inActionContext)
      throws ExecutionException {
    SetTabOrderRequest currentRequest = (SetTabOrderRequest) inActionContext.getParams();

    Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId());

    List<Tab> tabs = person.getTabs(currentRequest.getTabType());

    // Find the tab to be moved
    int oldIndex = findTabIndex(tabs, currentRequest.getTabId());

    Tab movingTab = tabs.get(oldIndex);

    // move the tab
    tabs.remove(oldIndex);
    tabs.add(currentRequest.getNewIndex(), movingTab);

    personMapper.flush();

    return Boolean.TRUE;
  }