DefaultEntitlementCertServiceAdapter extends BaseEntitlementCertServiceAdapter { public Set<X509ExtensionWrapper> prepareV1Extensions(Set<Product> products, Pool pool, Consumer consumer, Integer quantity, String contentPrefix, Map<String, EnvironmentContent> promotedContent) { Set<X509ExtensionWrapper> result = new LinkedHashSet<>(); Set<String> entitledProductIds = entCurator.listEntitledProductIds( consumer, pool); int contentCounter = 0; boolean enableEnvironmentFiltering = config.getBoolean(ConfigProperties.ENV_CONTENT_FILTERING); Product skuProd = pool.getProduct(); for (Product prod : Collections2.filter(products, X509Util.PROD_FILTER_PREDICATE)) { log.debug("Adding X509 extensions for product: {}", prod); result.addAll(extensionUtil.productExtensions(prod)); Set<ProductContent> filteredContent = extensionUtil.filterProductContent( prod, consumer, promotedContent, enableEnvironmentFiltering, entitledProductIds, consumer.getOwner().isContentAccessEnabled()); filteredContent = extensionUtil.filterContentByContentArch(filteredContent, consumer, prod); contentCounter += filteredContent.size(); log.debug("Adding X509 extensions for content: {}", filteredContent); result.addAll(extensionUtil.contentExtensions(filteredContent, contentPrefix, promotedContent, consumer, skuProd)); } if (contentCounter > X509ExtensionUtil.V1_CONTENT_LIMIT) { String cause = i18n.tr("Too many content sets for certificate {0}. A newer " + "client may be available to address this problem. " + "See knowledge database https: "information.", pool.getProductName()); throw new CertificateSizeException(cause); } result.addAll(extensionUtil.subscriptionExtensions(pool)); result.addAll(extensionUtil.entitlementExtensions(quantity)); result.addAll(extensionUtil.consumerExtensions(consumer)); if (log.isDebugEnabled()) { for (X509ExtensionWrapper eWrapper : result) { log.debug("Extension {} with value {}", eWrapper.getOid(), eWrapper.getValue()); } } return result; } @Inject  DefaultEntitlementCertServiceAdapter(PKIUtility pki,
        X509ExtensionUtil extensionUtil,
        X509V3ExtensionUtil v3extensionUtil,
        EntitlementCertificateCurator entCertCurator,
        KeyPairCurator keyPairCurator,
        CertificateSerialCurator serialCurator,
        OwnerCurator ownerCurator,
        EntitlementCurator entCurator, I18n i18n,
        Configuration config,
        ProductCurator productCurator,
        ConsumerTypeCurator consumerTypeCurator,
        EnvironmentCurator environmentCurator); @Override EntitlementCertificate generateEntitlementCert(Entitlement entitlement, Product product); @Override Map<String, EntitlementCertificate> generateEntitlementCerts(Consumer consumer,
        Map<String, PoolQuantity> poolQuantities, Map<String, Entitlement> entitlements,
        Map<String, Product> products, boolean save); X509Certificate createX509Certificate(Consumer consumer, Owner owner, Pool pool,
        Entitlement ent, Product product, Set<Product> products,
        List<org.candlepin.model.dto.Product> productModels, BigInteger serialNumber,
        KeyPair keyPair, boolean useContentPrefix); Set<X509ExtensionWrapper> prepareV1Extensions(Set<Product> products,
        Pool pool, Consumer consumer, Integer quantity, String contentPrefix,
        Map<String, EnvironmentContent> promotedContent); Set<X509ExtensionWrapper> prepareV3Extensions(); Set<X509ByteExtensionWrapper> prepareV3ByteExtensions(Product sku,
        List<org.candlepin.model.dto.Product> productModels, String contentPrefix,
        Map<String, EnvironmentContent> promotedContent); String cleanUpPrefix(String contentPrefix); List<Long> listEntitlementSerialIds(Consumer consumer);  }
@Test public void testPrepareV1Extensions() { Set<Product> products = new HashSet<>(); products.add(product); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertTrue(isEncodedContentValid(map)); assertTrue(map.containsKey(CONTENT_URL)); assertTrue(extMapHasContentType(content, extMap, "1")); assertFalse(extMapHasContentType(content, extMap, "2")); }
@Test public void testPrepareV1ExtensionsBrandedProduct() { Set<Product> products = new HashSet<>(); product.setAttribute(Product.Attributes.BRANDING_TYPE, "os"); products.add(product); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertTrue(isEncodedContentValid(map)); assertTrue(extMapHasProductBrandType(product, extMap)); assertTrue(extMapProductBrandTypeMatches(product, extMap, "os")); }
@Test public void testPrepareV1ExtensionsNoCompatibleArch() { Set<Product> products = new HashSet<>(); Product wrongArchProduct = TestUtil.createProduct("12345", "a product"); wrongArchProduct.setAttribute(Product.Attributes.VERSION, "version"); wrongArchProduct.setAttribute(Product.Attributes.VARIANT, "variant"); wrongArchProduct.setAttribute(Product.Attributes.TYPE, "SVC"); wrongArchProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL"); String wrongArches = "s390x,s390,ppc64,ia64"; Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, wrongArches); wrongArchProduct.addContent(wrongArchContent, false); products.add(wrongArchProduct); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertFalse(isEncodedContentValid(map)); assertFalse(map.containsKey(CONTENT_URL)); assertFalse(extMapHasContentType(kickstartContent, extMap, "null")); }
@Test public void testPrepareV1ExtensionsKickstartContent() { Set<Product> products = new HashSet<>(); Product kickstartProduct = TestUtil.createProduct("12345", "a product"); kickstartProduct.setAttribute(Product.Attributes.VERSION, "version"); kickstartProduct.setAttribute(Product.Attributes.VARIANT, "variant"); kickstartProduct.setAttribute(Product.Attributes.TYPE, "SVC"); kickstartProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL"); kickstartProduct.addContent(kickstartContent, false); products.add(kickstartProduct); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertTrue(isEncodedContentValid(map)); assertTrue(map.containsKey(CONTENT_TYPE_KICKSTART)); assertTrue(map.containsKey(CONTENT_URL)); assertFalse(extMapHasContentType(kickstartContent, extMap, "1")); assertFalse(extMapHasContentType(kickstartContent, extMap, "2")); assertTrue(extMapHasContentType(kickstartContent, extMap, "3")); assertFalse(extMapHasContentType(kickstartContent, extMap, "null")); }
@Test public void testPrepareV1ExtensionsFileContent() { Set<Product> products = new HashSet<>(); Product fileProduct = TestUtil.createProduct("12345", "a product"); fileProduct.setAttribute(Product.Attributes.VERSION, "version"); fileProduct.setAttribute(Product.Attributes.VARIANT, "variant"); fileProduct.setAttribute(Product.Attributes.TYPE, "SVC"); fileProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL"); fileProduct.addContent(fileContent, false); products.clear(); products.add(fileProduct); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertTrue(isEncodedContentValid(map)); assertTrue(map.containsKey(CONTENT_TYPE_FILE)); assertTrue(map.containsKey(CONTENT_URL)); assertFalse(extMapHasContentType(fileContent, extMap, "1")); assertTrue(extMapHasContentType(fileContent, extMap, "2")); assertFalse(extMapHasContentType(fileContent, extMap, "3")); assertFalse(extMapHasContentType(fileContent, extMap, "null")); }
@Test public void testPrepareV1ExtensionsFileUnknownContentType() { Set<Product> products = new HashSet<>(); Product unknownContentTypeProduct = TestUtil.createProduct("12345", "a product"); unknownContentTypeProduct.setAttribute(Product.Attributes.VERSION, "version"); unknownContentTypeProduct.setAttribute(Product.Attributes.VARIANT, "variant"); unknownContentTypeProduct.setAttribute(Product.Attributes.TYPE, "SVC"); unknownContentTypeProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL); unknownContentTypeProduct.addContent(unknownTypeContent, false); products.clear(); products.add(unknownContentTypeProduct); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertFalse(isEncodedContentValid(map)); assertFalse(map.containsKey(CONTENT_URL_UNKNOWN_TYPE)); assertFalse(map.containsKey(CONTENT_TYPE_UNKNOWN)); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "1")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "2")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "3")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "null")); }
@Test public void testPrepareV1ExtensionsKnownAndUnknownContentTypes() { Set<Product> products = new HashSet<>(); Product product = TestUtil.createProduct("12345", "a product"); product.setAttribute(Product.Attributes.VERSION, "version"); product.setAttribute(Product.Attributes.VARIANT, "variant"); product.setAttribute(Product.Attributes.TYPE, "SVC"); product.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL); product.addContent(content, false); product.addContent(fileContent, false); product.addContent(kickstartContent, false); product.addContent(unknownTypeContent, false); products.add(product); setupEntitlements(ARCH_LABEL, "1.0"); Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null); Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions); Map<String, String> extMap = getEncodedContentMap(extensions); assertTrue(isEncodedContentValid(map)); assertTrue(map.containsKey(CONTENT_URL)); assertFalse(map.containsKey(CONTENT_TYPE_UNKNOWN)); assertFalse(map.containsKey(CONTENT_URL_UNKNOWN_TYPE)); assertTrue(extMapHasContentType(content, extMap, "1")); assertTrue(extMapHasContentType(fileContent, extMap, "2")); assertTrue(extMapHasContentType(kickstartContent, extMap, "3")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "1")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "2")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "3")); assertFalse(extMapHasContentType(unknownTypeContent, extMap, "null")); }