Exemplo n.º 1
0
  public void testOrgDefautRegistrationToken() throws Exception {
    User user = UserTestUtils.findNewUser("testUser", "testOrg", true);
    Org orig = user.getOrg();
    orig.setName("org created by OrgFactory test: " + TestUtils.randomString());
    // build the channels set
    Channel channel1 = ChannelFactoryTest.createTestChannel(orig);
    flushAndEvict(channel1);
    orig.addOwnedChannel(channel1);
    orig = OrgFactory.save(orig);
    assertTrue(orig.getId().longValue() > 0);

    assertNull(orig.getToken());
    ActivationKey key = ActivationKeyTest.createTestActivationKey(user);
    // Token is hidden behind activation key so we have to look it up
    // manually:
    Token token = TokenFactory.lookupById(key.getId());
    orig.setToken(token);
    orig = OrgFactory.save(orig);
    Long origId = orig.getId();
    flushAndEvict(orig);

    Org lookup = OrgFactory.lookupById(origId);
    assertEquals(token.getId(), lookup.getToken().getId());
    lookup.setToken(null);
    flushAndEvict(lookup);

    lookup = OrgFactory.lookupById(origId);
    assertNull(lookup.getToken());
  }
Exemplo n.º 2
0
  /**
   * Delete an organization.
   *
   * @param sessionKey User's session key.
   * @param orgId ID of organization to delete.
   * @return 1 on success, exception thrown otherwise.
   * @xmlrpc.doc Delete an organization. The default organization (i.e. orgId=1) cannot be deleted.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("int", "orgId")
   * @xmlrpc.returntype #return_int_success()
   */
  public int delete(String sessionKey, Integer orgId) {
    User user = getSatAdmin(sessionKey);
    Org org = verifyOrgExists(orgId);

    // Verify we're not trying to delete the default org (id 1):
    Org defaultOrg = OrgFactory.getSatelliteOrg();
    if (orgId.longValue() == defaultOrg.getId().longValue()) {
      throw new SatelliteOrgException();
    }

    OrgFactory.deleteOrg(org.getId(), user);

    return 1;
  }
Exemplo n.º 3
0
  /**
   * List an organization's allocation of a system entitlement.
   *
   * @param sessionKey User's session key.
   * @param label System entitlement label.
   * @param includeUnentitled If true, the result will include both organizations that have the
   *     entitlement as well as those that do not; otherwise, the result will only include
   *     organizations that have the entitlement.
   * @return a list of Maps having the system entitlements info.
   * @since 10.4
   * @xmlrpc.doc List each organization's allocation of a system entitlement.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("string", "label")
   * @xmlrpc.param #param_desc("boolean", "includeUnentitled", "If true, the result will include
   *     both organizations that have the entitlement as well as those that do not; otherwise, the
   *     result will only include organizations that have the entitlement.")
   * @xmlrpc.returntype #array() #struct("entitlement usage") #prop("int", "org_id") #prop("string",
   *     "org_name") #prop("int", "allocated") #prop("int", "unallocated") #prop("int", "used")
   *     #prop("int", "free") #struct_end() #array_end()
   */
  public List<Map> listSystemEntitlements(
      String sessionKey, String label, Boolean includeUnentitled) {

    getSatAdmin(sessionKey);
    verifyEntitlementExists(label);

    DataList<Map> result = null;
    if (includeUnentitled) {
      result = OrgManager.allOrgsSingleEntitlementWithEmptyOrgs(label);
    } else {
      result = OrgManager.allOrgsSingleEntitlement(label);
    }

    List<Map> details = new LinkedList<Map>();
    for (Map row : result) {
      Map<String, Object> map = new HashMap<String, Object>();
      Org org = OrgFactory.lookupById((Long) row.get("orgid"));
      map.put(ORG_ID_KEY, new Integer(org.getId().intValue()));
      map.put(ORG_NAME_KEY, org.getName());
      map.put(ALLOCATED_KEY, ((Long) row.get("total")).intValue());
      map.put(USED_KEY, row.get("usage"));
      long free = (Long) row.get("total") - (Long) row.get("usage");
      map.put(FREE_KEY, free);
      long unallocated = (Long) row.get("upper") - (Long) row.get("total");
      map.put(UN_ALLOCATED_KEY, unallocated);
      details.add(map);
    }
    return details;
  }
Exemplo n.º 4
0
 /** {@inheritDoc} */
 public List<OrgTrust> getResult(RequestContext ctx) {
   Org org = ctx.getCurrentUser().getOrg();
   Set<Org> trustedorgs = org.getTrustedOrgs();
   List<OrgTrust> trusts = new ArrayList<OrgTrust>();
   for (Org o : trustedorgs) {
     DataResult<Map<String, Object>> dr = SystemManager.sidsInOrgTrust(org.getId(), o.getId());
     OrgTrust trust = new OrgTrust(o);
     if (!dr.isEmpty()) {
       for (Map<String, Object> m : dr) {
         Long sid = (Long) m.get("id");
         trust.getSubscribed().add(sid);
       }
     }
     trusts.add(trust);
   }
   return trusts;
 }
Exemplo n.º 5
0
 public void testOrgTrust() throws Exception {
   Org org = createTestOrg();
   Org trusted = createTestOrg();
   org.getTrustedOrgs().add(trusted);
   OrgFactory.save(org);
   flushAndEvict(org);
   org = OrgFactory.lookupById(org.getId());
   trusted = OrgFactory.lookupById(trusted.getId());
   assertContains(org.getTrustedOrgs(), trusted);
   assertContains(trusted.getTrustedOrgs(), org);
   org.getTrustedOrgs().remove(trusted);
   OrgFactory.save(org);
   flushAndEvict(org);
   org = OrgFactory.lookupById(org.getId());
   trusted = OrgFactory.lookupById(trusted.getId());
   assertFalse(org.getTrustedOrgs().contains(trusted));
   assertFalse(trusted.getTrustedOrgs().contains(org));
 }
Exemplo n.º 6
0
 public void testCommitOrg() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   String changedName = "OrgFactoryTest testCommitOrg " + TestUtils.randomString();
   org1.setName(changedName);
   org1 = OrgFactory.save(org1);
   Long id = org1.getId();
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(id);
   assertEquals(changedName, org2.getName());
 }
Exemplo n.º 7
0
 public void testStagingContent() throws Exception {
   Org org1 = createTestOrg();
   boolean staging = org1.getOrgConfig().isStagingContentEnabled();
   Long id = org1.getId();
   org1.getOrgConfig().setStagingContentEnabled(!staging);
   OrgFactory.save(org1);
   assertEquals(!staging, org1.getOrgConfig().isStagingContentEnabled());
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(id);
   assertEquals(!staging, org2.getOrgConfig().isStagingContentEnabled());
 }
Exemplo n.º 8
0
 private Org createTestOrg() throws Exception {
   Org org1 = OrgFactory.createOrg();
   org1.setName("org created by OrgFactory test: " + TestUtils.randomString());
   org1 = OrgFactory.save(org1);
   // build the channels set
   Channel channel1 = ChannelFactoryTest.createTestChannel(org1);
   flushAndEvict(channel1);
   org1.addOwnedChannel(channel1);
   assertTrue(org1.getId().longValue() > 0);
   return org1;
 }
Exemplo n.º 9
0
 /**
  * Test the addition of an entitlement to an org This code should be refactored into a business
  * method of some sort if it becomes necessary to actually add entitlements progmatically from
  * within the Java code. For now we need this test because new Orgs don't have any entitlements.
  */
 public void testAddEntitlement() throws Exception {
   // Create a new Org and add an Entitlement
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   Set entitlements = org1.getEntitlements();
   OrgEntitlementType oet = OrgFactory.lookupEntitlementByLabel("sw_mgr_enterprise");
   entitlements.add(oet);
   org1.setEntitlements(entitlements);
   org1 = OrgFactory.save(org1);
   Long orgId = org1.getId();
   // Re-lookup the object and test it
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(orgId);
   assertTrue(org2.hasEntitlement(oet));
 }
 /**
  * Constructor
  *
  * @param channelFamilyLabel label of entitlement to update
  * @param orgIn to update totals for
  * @param newTotalIn This is the *proposed* new total for the org you are passing in.
  * @param newFlexTotalIn This is the *proposed* new flex total for the org you are passing in.
  */
 public UpdateOrgSoftwareEntitlementsCommand(
     String channelFamilyLabel, Org orgIn, Long newTotalIn, Long newFlexTotalIn) {
   if (orgIn.getId().equals(OrgFactory.getSatelliteOrg().getId())) {
     throw new IllegalArgumentException("Cant update the default org");
   }
   this.org = orgIn;
   this.newTotal = newTotalIn;
   this.newFlexTotal = newFlexTotalIn;
   this.channelFamily =
       ChannelFamilyFactory.lookupByLabel(channelFamilyLabel, OrgFactory.getSatelliteOrg());
   if (this.channelFamily == null) {
     throw new IllegalArgumentException("ChannelFamily not found: [" + channelFamilyLabel + "]");
   }
 }
Exemplo n.º 11
0
  /**
   * @param user User that owns parent channel
   * @param channelIn base channel to unsubscribe from.
   */
  private void unsubscribeOrgsFromChannel(User user, Channel channelIn, String accessIn) {
    Org org = channelIn.getOrg();

    // find trusted orgs
    Set<Org> trustedOrgs = org.getTrustedOrgs();
    for (Org o : trustedOrgs) {
      // find systems subscribed in org Trust
      DataResult<Map<String, Object>> dr = SystemManager.sidsInOrgTrust(org.getId(), o.getId());

      for (Map<String, Object> item : dr) {
        Long sid = (Long) item.get("id");
        Server s = ServerFactory.lookupById(sid);
        if (s.isSubscribed(channelIn)) {
          // check if this is a base custom channel
          if (channelIn.getParentChannel() == null) {
            // unsubscribe children first if subscribed
            List<Channel> children = channelIn.getAccessibleChildrenFor(user);
            Iterator<Channel> i = children.iterator();
            while (i.hasNext()) {
              Channel child = i.next();
              if (s.isSubscribed(child)) {
                // unsubscribe server from child channel

                child.getTrustedOrgs().remove(o);
                child.setAccess(accessIn);
                ChannelFactory.save(child);
                s = SystemManager.unsubscribeServerFromChannel(s, child);
              }
            }
          }
          // unsubscribe server from channel
          ChannelFactory.save(channelIn);
          s = SystemManager.unsubscribeServerFromChannel(s, channelIn);
        }
      }
    }
  }
Exemplo n.º 12
0
  /** @param orgIn */
  private void publishUpdateErrataCacheEvent(Org orgIn) {
    StopWatch sw = new StopWatch();
    if (log.isDebugEnabled()) {
      log.debug("Updating errata cache");
      sw.start();
    }

    UpdateErrataCacheEvent uece = new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG);
    uece.setOrgId(orgIn.getId());
    MessageQueue.publish(uece);

    if (log.isDebugEnabled()) {
      sw.stop();
      log.debug("Finished Updating errata cache. Took [" + sw.getTime() + "]");
    }
  }
Exemplo n.º 13
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;
  }
Exemplo n.º 14
0
 public void testLookupById() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   assertNotNull(org1);
   assertTrue(org1.getId().longValue() > 0);
 }
Exemplo n.º 15
0
 public void testCreateOrg() throws Exception {
   Org org1 = createTestOrg();
   Org org2 = OrgFactory.lookupById(org1.getId());
   assertEquals(org2.getName(), org1.getName());
   assertNotNull(org2.getOwnedChannels());
 }