Ejemplo n.º 1
0
  /** Set up the various providers which can be used to authenticate the user */
  public void setupAuthStrategies() {

    // use oauth
    if (config.oAuthEnabled()) {
      log.debug("OAuth Authentication is enabled.");
      TrustedConsumerAuth consumerAuth =
          new TrustedConsumerAuth(consumerCurator, deletedConsumerCurator, i18n);
      TrustedUserAuth userAuth = new TrustedUserAuth(userService, injector);
      TrustedExternalSystemAuth systemAuth = new TrustedExternalSystemAuth();
      providers.add(new OAuth(consumerAuth, userAuth, systemAuth, injector, config));
    }

    // basic http access
    if (config.basicAuthEnabled()) {
      log.debug("Basic Authentication is enabled.");
      providers.add(new BasicAuth(userService, injector));
    }
    // consumer certificates
    if (config.sslAuthEnabled()) {
      log.debug("Certificate Based Authentication is enabled.");
      providers.add(new SSLAuth(consumerCurator, deletedConsumerCurator, i18n));
    }
    // trusted headers
    if (config.trustedAuthEnabled()) {
      log.debug("Trusted Authentication is enabled.");
      providers.add(new TrustedConsumerAuth(consumerCurator, deletedConsumerCurator, i18n));
      providers.add(new TrustedUserAuth(userService, injector));
    }
  }
  @Test
  public void testBuildBaseUrlWithConfigPropertyEmpty() {
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(true);
    when(config.getString(eq(ConfigProperties.PREFIX_APIURL))).thenReturn("");
    when(request.getRequestURL()).thenReturn(new StringBuffer("https://example.com/candlepin"));

    UriBuilder builder = interceptor.buildBaseUrl(request);
    assertEquals("https://example.com/candlepin", builder.build().toString());
  }
Ejemplo n.º 3
0
 private void postBindVirtLimit(
     PoolHelper postHelper,
     Entitlement entitlement,
     Pool pool,
     Consumer c,
     Map<String, String> attributes) {
   log.debug("Running virt_limit post-bind.");
   if (!c.isManifest() && (config.standalone() || attributes.containsKey("host_limited"))) {
     String productId = pool.getProductId();
     String virtLimit = attributes.get("virt_limit");
     if ("unlimited".equals(virtLimit)) {
       postHelper.createHostRestrictedPool(productId, pool, "unlimited");
     } else {
       int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
       if (virtQuantity > 0) {
         postHelper.createHostRestrictedPool(productId, pool, String.valueOf(virtQuantity));
       }
     }
   } else {
     if (!config.standalone() && c.isManifest()) {
       String virtLimit = attributes.get("virt_limit");
       if (!"unlimited".equals(virtLimit)) {
         // if the bonus pool is not unlimited, then the bonus pool
         // quantity
         // needs to be adjusted based on the virt limit
         int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
         if (virtQuantity > 0) {
           List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
           for (int idex = 0; idex < pools.size(); idex++) {
             Pool derivedPool = pools.get(idex);
             if (derivedPool.getAttributeValue("pool_derived") != null) {
               derivedPool = postHelper.updatePoolQuantity(derivedPool, -1 * virtQuantity);
             }
           }
         }
       } else {
         // if the bonus pool is unlimited, then the quantity needs
         // to go to 0
         // when the physical pool is exhausted completely by export.
         // A quantity of 0 will block future binds, whereas -1 does
         // not.
         if (pool.getQuantity().equals(pool.getExported())) {
           // getting all pools matching the sub id. Filtering out
           // the 'parent'.
           List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
           for (int idex = 0; idex < pools.size(); idex++) {
             Pool derivedPool = pools.get(idex);
             if (derivedPool.getAttributeValue("pool_derived") != null) {
               derivedPool = postHelper.setPoolQuantity(derivedPool, 0);
             }
           }
         }
       }
     }
   }
 }
  @Test
  public void testBuildBaseUrlWithNoSchemeProvided() {
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(true);
    when(config.getString(eq(ConfigProperties.PREFIX_APIURL))).thenReturn("example.com/candlepin");
    when(request.getContextPath()).thenReturn("/candlepin");
    when(request.getRequestURI()).thenReturn("/candlepin/resource");

    UriBuilder builder = interceptor.buildBaseUrl(request);
    assertEquals("https://example.com/candlepin/resource", builder.build().toString());
  }
  @Test
  public void testPostProcessWithPaging() {
    when(page.getPageRequest()).thenReturn(pageRequest);
    when(page.getMaxRecords()).thenReturn(15);
    when(pageRequest.isPaging()).thenReturn(true);
    when(pageRequest.getPage()).thenReturn(2);
    when(pageRequest.getPerPage()).thenReturn(5);

    // We're going to take the quick path through buildBaseUrl.
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(false);
    when(request.getRequestURL()).thenReturn(new StringBuffer("https://example.com/candlepin"));
    when(request.getQueryString()).thenReturn("order=asc&page=1&per_page=10");

    MultivaluedMap<String, Object> map = new MultivaluedMapImpl<String, Object>();
    when(response.getMetadata()).thenReturn(map);

    ResteasyProviderFactory.pushContext(Page.class, page);
    ResteasyProviderFactory.pushContext(HttpServletRequest.class, request);

    interceptor.postProcess(response);
    String header = (String) map.getFirst(LinkHeaderPostInterceptor.LINK_HEADER);

    // It would be a bit much to parse the entire header, so let's just make
    // sure that we have first, last, next, and prev links.
    assertTrue(header.contains("rel=\"first\""));
    assertTrue(header.contains("rel=\"last\""));
    assertTrue(header.contains("rel=\"next\""));
    assertTrue(header.contains("rel=\"prev\""));
  }
Ejemplo n.º 6
0
 private String getWebAppPrefix() {
   String webAppPrefix = config.getString("candlepin.export.webapp.prefix");
   if (webAppPrefix != null && webAppPrefix.trim().equals("")) {
     webAppPrefix = null;
   }
   return webAppPrefix;
 }
  @Test
  public void testBuildBaseUrlWithBadUriReturnsNull() {
    when(config.containsKey(eq(ConfigProperties.PREFIX_APIURL))).thenReturn(false);
    when(request.getRequestURL()).thenReturn(new StringBuffer("^$&#**("));

    UriBuilder builder = interceptor.buildBaseUrl(request);
    assertNull(builder);
  }
Ejemplo n.º 8
0
  private String getCrlFilePath() {
    String filePath = config.getString(ConfigProperties.CRL_FILE_PATH);

    if (filePath == null) {
      throw new IseException("CRL file path not defined in config file");
    }

    return filePath;
  }
Ejemplo n.º 9
0
  @Test
  public void testRevokeCleansUpPoolsWithSourceEnt() throws Exception {
    Entitlement e =
        new Entitlement(
            pool, TestUtil.createConsumer(o), pool.getStartDate(), pool.getEndDate(), 1);
    List<Pool> poolsWithSource = createPoolsWithSourceEntitlement(e, product);
    when(mockPoolCurator.listBySourceEntitlement(e)).thenReturn(poolsWithSource);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    when(mockConfig.standalone()).thenReturn(true);

    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool);

    manager.revokeEntitlement(e);

    verify(entCertAdapterMock).revokeEntitlementCertificates(e);
    verify(entitlementCurator).delete(e);
  }
Ejemplo n.º 10
0
 private void postUnbindVirtLimit(
     PoolHelper postHelper,
     Entitlement entitlement,
     Pool pool,
     Consumer c,
     Map<String, String> attributes) {
   log.debug("Running virt_limit post unbind.");
   if (!config.standalone() && c.isManifest()) {
     String virtLimit = attributes.get("virt_limit");
     if (!"unlimited".equals(virtLimit)) {
       // As we have unbound an entitlement from a physical pool that
       // was previously
       // exported, we need to add back the reduced bonus pool
       // quantity.
       int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
       if (virtQuantity > 0) {
         List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
         for (int idex = 0; idex < pools.size(); idex++) {
           Pool derivedPool = pools.get(idex);
           if (derivedPool.getAttributeValue("pool_derived") != null) {
             postHelper.updatePoolQuantity(derivedPool, virtQuantity);
           }
         }
       }
     } else {
       // As we have unbound an entitlement from a physical pool that
       // was previously
       // exported, we need to set the unlimited bonus pool quantity to
       // -1.
       List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
       for (int idex = 0; idex < pools.size(); idex++) {
         Pool derivedPool = pools.get(idex);
         if (derivedPool.getAttributeValue("pool_derived") != null) {
           if (derivedPool.getQuantity() == 0) {
             postHelper.setPoolQuantity(derivedPool, -1);
           }
         }
       }
     }
   }
 }
Ejemplo n.º 11
0
  @Before
  public void init() throws Exception {
    product = TestUtil.createProduct();
    o = new Owner("key", "displayname");
    pool = TestUtil.createPool(o, product);

    when(mockConfig.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    this.productCache = new ProductCache(mockConfig, mockProductAdapter);

    this.principal = TestUtil.createOwnerPrincipal();
    this.manager =
        spy(
            new CandlepinPoolManager(
                mockPoolCurator,
                mockSubAdapter,
                productCache,
                entCertAdapterMock,
                mockEventSink,
                eventFactory,
                mockConfig,
                enforcerMock,
                poolRulesMock,
                entitlementCurator,
                consumerCuratorMock,
                certCuratorMock,
                complianceRules,
                envCurator,
                autobindRules));

    when(entCertAdapterMock.generateEntitlementCert(
            any(Entitlement.class), any(Subscription.class), any(Product.class)))
        .thenReturn(new EntitlementCertificate());

    dummyComplianceStatus = new ComplianceStatus(new Date());
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class)))
        .thenReturn(dummyComplianceStatus);
  }