Пример #1
0
  private void exportEntitlements(File baseDir, Consumer consumer)
      throws IOException, ExportCreationException {
    File entCertDir = new File(baseDir.getCanonicalPath(), "entitlements");
    entCertDir.mkdir();

    for (Entitlement ent : entitlementCurator.listByConsumer(consumer)) {
      if (ent.isDirty()) {
        log.error("Entitlement " + ent.getId() + " is marked as dirty.");
        throw new ExportCreationException("Attempted to export dirty entitlements");
      }

      if (!this.exportRules.canExport(ent)) {
        if (log.isDebugEnabled()) {
          log.debug(
              "Skipping export of entitlement with product: {}", ent.getPool().getProductId());
        }

        continue;
      }

      if (log.isDebugEnabled()) {
        log.debug("Exporting entitlement for product" + ent.getPool().getProductId());
      }
      FileWriter writer = null;
      try {
        File file = new File(entCertDir.getCanonicalPath(), ent.getId() + ".json");
        writer = new FileWriter(file);
        entExporter.export(mapper, writer, ent);
      } finally {
        if (writer != null) {
          writer.close();
        }
      }
    }
  }
Пример #2
0
  @Test(expected = ExportCreationException.class)
  public void doNotExportDirtyEntitlements() throws Exception {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    Consumer consumer = mock(Consumer.class);
    Entitlement ent = mock(Entitlement.class);
    Principal principal = mock(Principal.class);
    IdentityCertificate idcert = new IdentityCertificate();

    List<Entitlement> entitlements = new ArrayList<Entitlement>();
    entitlements.add(ent);

    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");

    when(ec.listByConsumer(consumer)).thenReturn(entitlements);
    when(ent.isDirty()).thenReturn(true);
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);

    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());

    Exporter e =
        new Exporter(
            ctc,
            me,
            ce,
            cte,
            re,
            ece,
            ecsa,
            pe,
            psa,
            pce,
            ec,
            ee,
            pki,
            config,
            exportRules,
            pprov,
            dvc,
            dve,
            cdnc,
            cdne);

    e.getFullExport(consumer);
  }