Ejemplo n.º 1
0
  private int enableAccess(User loggedInUser, String channelLabel, Integer orgId, boolean enable)
      throws FaultException {
    Channel channel = lookupChannelByLabel(loggedInUser, channelLabel);
    verifyChannelAdmin(loggedInUser, channel);

    if (!loggedInUser.getOrg().equals(channel.getOrg())) {
      // users are not allowed to alter properties for a channel that is in a
      // different org
      throw new NotPermittedByOrgException(
          loggedInUser.getOrg().getId().toString(),
          channel.getLabel(),
          channel.getOrg().getId().toString());
    }

    // protected mode only for modifying individual orgs
    if (!channel.getAccess().equals(Channel.PROTECTED)) {
      throw new InvalidChannelAccessException(channel.getAccess());
    }

    Org org = OrgFactory.lookupById(orgId.longValue());
    if (org == null) {
      throw new NoSuchOrgException(orgId.toString());
    }

    // need to validate that the org provided is in the list of orgs that may
    // be granted access
    List<OrgChannelDto> orgs = OrgManager.orgChannelTrusts(channel.getId(), loggedInUser.getOrg());
    boolean orgInTrust = false;

    for (OrgChannelDto orgDto : orgs) {
      if (orgDto.getId().equals(new Long(orgId))) {
        orgInTrust = true;
        break;
      }
    }

    if (orgInTrust) {
      if (enable) {
        channel.getTrustedOrgs().add(org);
      } else {
        channel.getTrustedOrgs().remove(org);
      }
      ChannelFactory.save(channel);
    } else {
      throw new OrgNotInTrustException(orgId);
    }

    return 1;
  }
Ejemplo n.º 2
0
  /**
   * List the organizations associated with the given channel that may be trusted.
   *
   * @param loggedInUser The current user
   * @param channelLabel The label for the channel
   * @return List of map entries indicating the orgs available and if access is enabled.
   * @throws FaultException A FaultException is thrown if: - The sessionKey is invalid - The
   *     channelLabel is invalid - The user doesn't have channel admin permissions
   * @xmlrpc.doc List the organizations associated with the given channel that may be trusted.
   * @xmlrpc.param #session_key()
   * @xmlrpc.param #param_desc("string", "channelLabel", "label of the channel")
   * @xmlrpc.returntype #array() #struct("org") #prop("int", "org_id") #prop("string", "org_name")
   *     #prop("boolean", "access_enabled") #struct_end() #array_end()
   */
  public List list(User loggedInUser, String channelLabel) throws FaultException {

    Channel channel = lookupChannelByLabel(loggedInUser, channelLabel);
    verifyChannelAdmin(loggedInUser, channel);

    if (!loggedInUser.getOrg().equals(channel.getOrg())) {
      // users are not allowed to access properties for a channel that is in a
      // different org
      throw new NotPermittedByOrgException(
          loggedInUser.getOrg().getId().toString(),
          channel.getLabel(),
          channel.getOrg().getId().toString());
    }

    // retrieve the orgs available to be "trusted" for this channel
    List<OrgChannelDto> orgs = OrgManager.orgChannelTrusts(channel.getId(), loggedInUser.getOrg());
    // retrieve the orgs that are trusted for this channel
    Set<Org> trustedOrgs = channel.getTrustedOrgs();

    // populate a result that includes all orgs that could be trusted with a boolean
    // that indicates if the orgs is indeed trusted.
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    for (OrgChannelDto orgDto : orgs) {
      Org org = OrgFactory.lookupById(orgDto.getId());

      if (org != null) {
        Map<String, Object> entry = new HashMap<String, Object>();

        entry.put("org_id", org.getId().intValue());
        entry.put("org_name", org.getName());
        if (trustedOrgs.contains(org)) {
          entry.put("access_enabled", Boolean.TRUE);
        } else {
          entry.put("access_enabled", Boolean.FALSE);
        }
        result.add(entry);
      }
    }
    return result;
  }