org.sonatype.nexus.repository.types.ProxyType Java Examples

The following examples show how to use org.sonatype.nexus.repository.types.ProxyType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HelmResourceIT.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateProxy() throws Exception {
  repos.createHelmProxy(PROXY_NAME, "http://example.com");

  AbstractRepositoryApiRequest request = createProxyRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(ProxyType.NAME, PROXY_NAME), request);
  assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());

  Repository repository = repositoryManager.get(request.getName());
  assertNotNull(repository);

  assertThat(repository.getConfiguration().attributes("storage")
          .get("strictContentTypeValidation"),
      is(false));
  repositoryManager.delete(PROXY_NAME);
}
 
Example #2
Source File: AptApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case HostedType.NAME:
      return new AptHostedApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createAptHostedRepositoriesAttributes(repository),
          createAptSigningRepositoriesAttributes(repository));
    case ProxyType.NAME:
      return new AptProxyApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createAptProxyRepositoriesAttributes(repository),
          getProxyAttributes(repository), getNegativeCacheAttributes(repository),
          getHttpClientAttributes(repository), getRoutingRuleName(repository));
  }
  return null;
}
 
Example #3
Source File: CleanupConfigurationValidatorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  when(configuration.getRepositoryName()).thenReturn(REPO_NAME);
  when(configuration.getAttributes()).thenReturn(attributes);
  when(cleanupAttributes.containsKey(POLICY_NAME_KEY)).thenReturn(true);
  when(cleanupAttributes.get(POLICY_NAME_KEY)).thenReturn(ImmutableSet.of(POLICY_NAME));
  when(attributes.containsKey(CLEANUP_KEY)).thenReturn(true);
  when(attributes.get(CLEANUP_KEY)).thenReturn(cleanupAttributes);
  when(cleanupPolicyStorage.get(POLICY_NAME)).thenReturn(cleanupPolicy);
  when(cleanupPolicy.getFormat()).thenReturn(FORMAT);
  when(constraintFactory.createViolation(anyString(), anyString())).thenReturn(constraintViolation);

  recipes.add(recipe);
  when(repositoryManager.getAllSupportedRecipes()).thenReturn(recipes);
  when(configuration.getRecipeName()).thenReturn(FORMAT + "-" + ProxyType.NAME);
  when(recipe.getType()).thenReturn(new ProxyType());
  when(recipe.getFormat()).thenReturn(new Format(FORMAT){});

  underTest = new CleanupConfigurationValidator(constraintFactory, repositoryManager, cleanupPolicyStorage);
}
 
Example #4
Source File: RResourceIT.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateProxy() throws Exception {
  repos.createRProxy(PROXY_NAME, REMOTE_URL);

  AbstractRepositoryApiRequest request = createProxyRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(ProxyType.NAME, PROXY_NAME), request);
  assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());

  Repository repository = repositoryManager.get(request.getName());
  assertNotNull(repository);

  assertThat(repository.getConfiguration().attributes("storage")
          .get("strictContentTypeValidation"),
      is(false));
  repositoryManager.delete(PROXY_NAME);
}
 
Example #5
Source File: RepairMetadataComponentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void whenTypeDoesNotMatchShouldNotRepair() {
  underTest = new RepairMetadataComponentForTest(repositoryManager, assetEntityAdapter, type, format)
  {
    @Override
    protected void doRepairRepository(final Repository repository) {
      throw new UnsupportedOperationException();
    }
  };

  when(repository.getType()).thenReturn(new ProxyType());

  try {
    underTest.repairRepository(repository);
  }
  catch (Exception e) {
    fail("repair should not have been attempted");
  }
}
 
Example #6
Source File: MavenApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case HostedType.NAME:
      return new MavenHostedApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createMavenAttributes(repository));
    case ProxyType.NAME:
      return new MavenProxyApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository), getRoutingRuleName(repository),
          createMavenAttributes(repository));
    default:
      return super.adapt(repository);
  }
}
 
Example #7
Source File: ProxyRepositoryApiRequest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("squid:S00107") // suppress constructor parameter count
@JsonCreator
public ProxyRepositoryApiRequest(
    @JsonProperty("name") final String name,
    @JsonProperty("format") final String format,
    @JsonProperty("online") final Boolean online,
    @JsonProperty("storage") final StorageAttributes storage,
    @JsonProperty("cleanup") final CleanupPolicyAttributes cleanup,
    @JsonProperty("proxy") final ProxyAttributes proxy,
    @JsonProperty("negativeCache") final NegativeCacheAttributes negativeCache,
    @JsonProperty("httpClient") final HttpClientAttributes httpClient,
    @JsonProperty("routingRule") final String routingRule)
{
  super(name, format, ProxyType.NAME, online);
  this.storage = storage;
  this.cleanup = cleanup;
  this.proxy = proxy;
  this.negativeCache = negativeCache;
  this.httpClient = httpClient;
  this.routingRule = routingRule;
}
 
Example #8
Source File: SimpleApiProxyRepository.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@JsonCreator
public SimpleApiProxyRepository(
    @JsonProperty("name") final String name,
    @JsonProperty("format") final String format,
    @JsonProperty("url") final String url,
    @JsonProperty("online") final Boolean online,
    @JsonProperty("storage") final StorageAttributes storage,
    @JsonProperty("cleanup") final CleanupPolicyAttributes cleanup,
    @JsonProperty("proxy") final ProxyAttributes proxy,
    @JsonProperty("negativeCache") final NegativeCacheAttributes negativeCache,
    @JsonProperty("httpClient") final HttpClientAttributes httpClient,
    @JsonProperty("routingRuleName") final String routingRuleName)
{
  super(name, format, ProxyType.NAME, url, online);
  this.storage = storage;
  this.cleanup = cleanup;
  this.proxy = proxy;
  this.negativeCache = negativeCache;
  this.httpClient = httpClient;
  this.routingRuleName = routingRuleName;
}
 
Example #9
Source File: SimpleApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String format = repository.getFormat().toString();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case GroupType.NAME:
      return new SimpleApiGroupRepository(name, format, url, online, getStorageAttributes(repository),
          getGroupAttributes(repository));
    case HostedType.NAME:
      return new SimpleApiHostedRepository(name, format, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository));
    case ProxyType.NAME:
      return new SimpleApiProxyRepository(name, format, url, online, getStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository),
          getRoutingRuleName(repository));
    default:
      return null;
  }
}
 
Example #10
Source File: ConanResourceIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateProxy() throws Exception {
  repos.createConanProxy(PROXY_NAME, REMOTE_URL);

  AbstractRepositoryApiRequest request = createProxyRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(ProxyType.NAME, PROXY_NAME), request);
  assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());

  Repository repository = repositoryManager.get(request.getName());
  assertNotNull(repository);

  assertThat(repository.getConfiguration().attributes("storage")
          .get("strictContentTypeValidation"),
      is(false));
  repositoryManager.delete(PROXY_NAME);
}
 
Example #11
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAdapt_proxyRepository_negativeCache() throws Exception {
  Repository repository = createRepository(new ProxyType());

  SimpleApiProxyRepository proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getNegativeCache().getEnabled(), is(true));
  assertThat(proxyRepository.getNegativeCache().getTimeToLive(), is(Time.hours(24).toMinutesI()));

  // Test specified values
  NestedAttributesMap negativeCache = repository.getConfiguration().attributes("negativeCache");
  negativeCache.set("enabled", false);
  negativeCache.set("timeToLive", 23.0); // specifically a double here to ensure exceptions not thrown

  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getNegativeCache().getEnabled(), is(false));
  assertThat(proxyRepository.getNegativeCache().getTimeToLive(), is(23));
}
 
Example #12
Source File: P2RepositoriesApiResourceIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateProxy() throws Exception {
  repos.createP2Proxy(PROXY_NAME, REMOTE_URL);

  AbstractRepositoryApiRequest request = createProxyRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(ProxyType.NAME, PROXY_NAME), request);
  assertEquals(response.getStatus(), Status.NO_CONTENT.getStatusCode());

  Repository repository = repositoryManager.get(request.getName());
  assertNotNull(repository);

  assertThat(repository.getConfiguration().attributes(StorageFacetConstants.STORAGE)
          .get(StorageFacetConstants.STRICT_CONTENT_TYPE_VALIDATION),
      is(false));
  repositoryManager.delete(PROXY_NAME);
}
 
Example #13
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAdapt_proxyRepositoryConnection() throws Exception {
  Repository repository = createRepository(new ProxyType());

  // defaults
  SimpleApiProxyRepository proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getHttpClient().getConnection(), nullValue());

  // test empty connection
  NestedAttributesMap connection = repository.getConfiguration().attributes("httpclient").child("connection");
  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertConnection(proxyRepository.getHttpClient().getConnection(), /* circular redirects */ false,
      /* cookies */ false, /* retries */ null, /* timeout */ null, null);

  // populate values
  connection.set("enableCircularRedirects", true);
  connection.set("enableCookies", true);
  connection.set("retries", 9.0);
  connection.set("timeout", 7.0);
  connection.set("userAgentSuffix", "hi-yall");

  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertConnection(proxyRepository.getHttpClient().getConnection(), /* circular redirects */ true, /* cookies */ true,
      /* retries */ 9, /* timeout */ 7, "hi-yall");
}
 
Example #14
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void invalidateCacheProxyRepository() throws Exception {
  when(repository.getType()).thenReturn(new ProxyType());
  ProxyFacet proxyFacet = mock(ProxyFacet.class);
  when(repository.facet(ProxyFacet.class)).thenReturn(proxyFacet);
  NegativeCacheFacet negativeCacheFacet = mock(NegativeCacheFacet.class);
  when(repository.facet(NegativeCacheFacet.class)).thenReturn(negativeCacheFacet);

  authorizingRepositoryManager.invalidateCache("repository");

  verify(repositoryManager).get(eq("repository"));
  verify(repositoryPermissionChecker).ensureUserCanAdmin(eq(EDIT), eq(repository));
  verify(repository).facet(ProxyFacet.class);
  verify(proxyFacet).invalidateProxyCaches();
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, proxyFacet);
}
 
Example #15
Source File: HelmResourceIT.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void updateProxy_noAuthz() throws Exception {
  repos.createHelmProxy(PROXY_NAME, "http://example.com");

  setUnauthorizedUser();
  AbstractRepositoryApiRequest request = createProxyRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(ProxyType.NAME, PROXY_NAME), request);
  assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
}
 
Example #16
Source File: OrientPyPiDeleteLegacyProxyAssetsTaskTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() {
  underTest = new OrientPyPiDeleteLegacyProxyAssetsTask(directories, repositoryManager);

  pyPiProxy =
      mockRepository(new PyPiFormat(), new ProxyType(), mockAsset("simple/"), mockAsset("simple/foo"),
          mockAsset("packages/00/01/02/foo-123.whl"), mockAsset("packages/foo/123/foo-123.whl"));
  pyPiHosted = mockRepository(new PyPiFormat(), new HostedType());
  otherProxy = mockRepository(mock(Format.class), new ProxyType());

  when(repositoryManager.browse()).thenReturn(Arrays.asList(pyPiProxy, pyPiHosted, otherProxy));
}
 
Example #17
Source File: NpmRepairPackageRootComponentTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  initialiseRepository(npmHosted, new HostedType(), new NpmFormat());
  initialiseRepository(npmProxy, new ProxyType(), new NpmFormat());
  initialiseRepository(npmGroup, new GroupType(), new NpmFormat());
  initialiseRepository(nonNpmFormat, new HostedType(), new Format("non-npm") { });
}
 
Example #18
Source File: NpmAuditTarballFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private AuditRepositoryComponent download(final AuditComponent auditComponent) throws TarballLoadingException {
  checkNotNull(auditComponent);
  String packageName = auditComponent.getName();
  String packageVersion = auditComponent.getVersion();
  String repositoryPath = NpmMetadataUtils.createRepositoryPath(packageName, packageVersion);
  final Request request = new Request.Builder()
      .action(GET)
      .path("/" + repositoryPath)
      .build();
  Repository repository = getRepository();
  Context context = new Context(repository, request);
  Matcher tarballMatcher = tarballMatcher(GET)
      .handler(new EmptyHandler()).create().getMatcher();
  tarballMatcher.matches(context);
  context.getAttributes().set(ProxyTarget.class, TARBALL);

  Optional<String> hashsumOpt;
  String repositoryType = repository.getType().getValue();
  if (repositoryType.equals(GroupType.NAME)) {
    hashsumOpt = tarballGroupHandler.getTarballHashsum(context);
  }
  else if (repositoryType.equals(ProxyType.NAME)) {
    hashsumOpt = getComponentHashsumForProxyRepo(repository, context);
  }
  else {
    // for an npm-hosted repository is no way to get npm package hashsum info.
    String errorMsg = String.format("The %s repository is not supported", repositoryType);
    throw new UnsupportedOperationException(errorMsg);
  }
  String hashsum = hashsumOpt.orElseThrow(() ->
      new TarballLoadingException(String.format("Can't get hashsum for the %s package", auditComponent)));
  return new AuditRepositoryComponent(auditComponent.getPackageType(), repositoryPath, hashsum);
}
 
Example #19
Source File: RoutingRulesResource.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@GET
@Path("/preview")
@RequiresPermissions("nexus:*")
@RequiresAuthentication
public RoutingRulePreviewXO getRoutingRulesPreview(@QueryParam("path") final String path,
                                                   @QueryParam("filter") final String filter)
{
  Map<Class<?>, List<Repository>> repositoriesByType = stream(repositoryManager.browse())
      .collect(groupingBy(r -> r.getType().getClass()));
  List<Repository> groupRepositories = repositoriesByType.get(GroupType.class);
  List<Repository> proxyRepositories = repositoriesByType.get(ProxyType.class);

  Map<RoutingRule, Boolean> routingRulePathMapping = routingRuleStore.list().stream()
      .collect(toMap(identity(), (RoutingRule rule) -> routingRuleHelper.isAllowed(rule, path)));

  final Stream<Repository> repositories;
  if (GROUPS.equals(filter)) {
    repositories = groupRepositories.stream();
  }
  else if (PROXIES.equals(filter)) {
    repositories = proxyRepositories.stream();
  }
  else {
    repositories = Stream.of(groupRepositories, proxyRepositories).flatMap(Collection::stream);
  }

  List<RoutingRulePreviewXO> rootRepositories = repositories.map(repository -> {
    List<Repository> children = repository.optionalFacet(GroupFacet.class)
        .map(facet -> facet.members()).orElse(null);
    return toPreviewXO(repository, children, routingRulePathMapping);
  }).collect(toList());

  return RoutingRulePreviewXO.builder().children(rootRepositories).expanded(!rootRepositories.isEmpty()).expandable(true).build();
}
 
Example #20
Source File: MavenApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_proxyRepository() throws Exception {
  Repository repository = createRepository(new ProxyType(), LayoutPolicy.STRICT, VersionPolicy.MIXED);

  MavenProxyApiRepository proxyRepository = (MavenProxyApiRepository) underTest.adapt(repository);
  assertRepository(proxyRepository, "proxy", true);
  assertThat(proxyRepository.getMaven().getLayoutPolicy(), is("STRICT"));
  assertThat(proxyRepository.getMaven().getVersionPolicy(), is("MIXED"));
  // Check fields are populated, actual values validated with SimpleApiRepositoryAdapterTest
  assertThat(proxyRepository.getCleanup(), nullValue());
  assertThat(proxyRepository.getHttpClient(), notNullValue());
  assertThat(proxyRepository.getNegativeCache(), notNullValue());
  assertThat(proxyRepository.getProxy(), notNullValue());
  assertThat(proxyRepository.getStorage(), notNullValue());
}
 
Example #21
Source File: OrientPyPiDeleteLegacyProxyAssetsTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Object execute() throws Exception {
  stream(repositoryManager.browse())
      .peek(r -> log.debug("Looking at repository: {}", r))
      .filter(r -> r.getFormat() instanceof PyPiFormat)
      .peek(r -> log.debug("Looking at PyPi repository: {}", r))
      .filter(r -> r.getType() instanceof ProxyType)
      .peek(r -> log.debug("Found PyPi proxy repository: {}", r))
      .forEach(this::deleteLegacyAssets);
  if (Files.exists(markerFile)) {
    Files.delete(markerFile);
  }
  return null;
}
 
Example #22
Source File: AptApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_proxyRepository() throws Exception {
  Repository repository = createRepository(new ProxyType(), "bionic", null, null, true);

  AptProxyApiRepository proxyRepository = (AptProxyApiRepository) underTest.adapt(repository);
  assertRepository(proxyRepository, "proxy", true);
  assertThat(proxyRepository.getApt().getDistribution(), is("bionic"));
  assertThat(proxyRepository.getApt().getFlat(), is(true));
}
 
Example #23
Source File: RepositoryBrowseResourceTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void before() throws Exception {
  when(uriInfo.getAbsolutePath()).thenReturn(UriBuilder.fromPath(URL_PREFIX + "central/").build());

  when(securityHelper.allPermitted(any())).thenReturn(true);
  when(templateHelper.parameters()).thenReturn(new TemplateParameters());
  when(templateHelper.render(any(),any())).thenReturn("something");
  when(repository.getName()).thenReturn(REPOSITORY_NAME);
  when(repository.getFormat()).thenReturn(new Format("format") {});
  when(repository.getType()).thenReturn(new ProxyType());

  when(repository.optionalFacet(GroupFacet.class)).thenReturn(Optional.empty());

  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.txSupplier()).thenReturn(txSupplier);
  when(txSupplier.get()).thenReturn(storageTx);

  when(storageTx.findAsset(any())).thenReturn(asset);

  EntityId bucketId = mock(EntityId.class);
  when(asset.bucketId()).thenReturn(bucketId);
  when(bucketStore.getById(bucketId)).thenReturn(bucket);
  when(bucket.getRepositoryName()).thenReturn(REPOSITORY_NAME);


  BrowseNode<EntityId> orgBrowseNode = browseNode("org");
  when(browseNodeStore.getByPath(REPOSITORY_NAME, Collections.emptyList(), configuration.getMaxHtmlNodes()))
      .thenReturn(Collections.singleton(orgBrowseNode));

  BrowseNode<EntityId> sonatypeBrowseNode = browseNode("sonatype");
  when(browseNodeStore.getByPath(REPOSITORY_NAME, Collections.singletonList("org"), configuration.getMaxHtmlNodes()))
      .thenReturn(Collections.singleton(sonatypeBrowseNode));
  when(repositoryManager.get(REPOSITORY_NAME)).thenReturn(repository);

  underTest = new RepositoryBrowseResource(repositoryManager, browseNodeStore, configuration, bucketStore,
      templateHelper, securityHelper);
}
 
Example #24
Source File: RoutingRuleHelperImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private List<Permission> getRepositoryAddPermissions() {
  if (null == repositoryAddPermissions) {
    repositoryAddPermissions = repositoryManager.getAllSupportedRecipes().stream()
        .filter(r -> r.getType().getValue().equals(ProxyType.NAME))
        .map(r -> new RepositoryAdminPermission(r.getFormat().getValue(), "*", singletonList(ADD)))
        .collect(toList());
  }
  return repositoryAddPermissions;
}
 
Example #25
Source File: RepositoryCacheUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Invalidates the group or proxy caches of the specified repository based on type.
 *
 * This is a no-op for hosted repositories.
 */
public static void invalidateCaches(final Repository repository) {
  checkNotNull(repository);
  if (GroupType.NAME.equals(repository.getType().getValue())) {
    invalidateGroupCaches(repository);
  } else if (ProxyType.NAME.equals(repository.getType().getValue())) {
    invalidateProxyAndNegativeCaches(repository);
  }
}
 
Example #26
Source File: RepositoryCacheUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Invalidates the proxy and negative caches for given repository.
 */
public static void invalidateProxyAndNegativeCaches(final Repository repository) {
  checkNotNull(repository);
  checkArgument(ProxyType.NAME.equals(repository.getType().getValue()));
  ProxyFacet proxyFacet = repository.facet(ProxyFacet.class);
  proxyFacet.invalidateProxyCaches();
  NegativeCacheFacet negativeCacheFacet = repository.facet(NegativeCacheFacet.class);
  negativeCacheFacet.invalidate();
}
 
Example #27
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_proxyRepository() throws Exception {
  Repository repository = createRepository(new ProxyType());

  NestedAttributesMap proxy = repository.getConfiguration().attributes("proxy");
  proxy.set("remoteUrl", "https://repo1.maven.org/maven2/");

  SimpleApiProxyRepository proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertRepository(proxyRepository, "proxy", true);

  assertThat(proxyRepository.getProxy().getContentMaxAge(), is(1440));
  assertThat(proxyRepository.getProxy().getMetadataMaxAge(), is(1440));
  assertThat(proxyRepository.getProxy().getRemoteUrl(), is("https://repo1.maven.org/maven2/"));
  assertThat(proxyRepository.getHttpClient().getAutoBlock(), is(false));
  assertThat(proxyRepository.getHttpClient().getBlocked(), is(false));

  // Test specified values
  proxy.set("contentMaxAge", 1000.0); // specifically a double here to ensure exceptions not thrown
  proxy.set("metadataMaxAge", 1000.0); // specifically a double here to ensure exceptions not thrown

  NestedAttributesMap httpclient = repository.getConfiguration().attributes("httpclient");
  httpclient.set("autoBlock", true);
  httpclient.set("blocked", true);

  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);

  assertThat(proxyRepository.getProxy().getContentMaxAge(), is(1000));
  assertThat(proxyRepository.getProxy().getMetadataMaxAge(), is(1000));
  assertThat(proxyRepository.getHttpClient().getAutoBlock(), is(true));
  assertThat(proxyRepository.getHttpClient().getBlocked(), is(true));
}
 
Example #28
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_proxyRepositoryRoutingRule() throws Exception {
  Repository repository = createRepository(new ProxyType());
  EntityId entityId = mock(EntityId.class);
  repository.getConfiguration().setRoutingRuleId(entityId);

  SimpleApiProxyRepository proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getRoutingRuleName(), nullValue());

  when(routingRuleStore.getById(any())).thenReturn(new OrientRoutingRule(ROUTING_RULE_NAME, null, null, null));

  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getRoutingRuleName(), is(ROUTING_RULE_NAME));
}
 
Example #29
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_proxyRepositoryStorageAttributes() throws Exception {
  Repository repository = createRepository(new ProxyType());
  setStorageAttributes(repository, "default", /* non-default */ false, null);

  SimpleApiProxyRepository proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);

  assertThat(proxyRepository.getStorage().getBlobStoreName(), is("default"));
  assertThat(proxyRepository.getStorage().getStrictContentTypeValidation(), is(false));
}
 
Example #30
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_proxyRepositoryAuth() throws Exception {
  Repository repository = createRepository(new ProxyType());

  // defaults
  SimpleApiProxyRepository proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getHttpClient().getAuthentication(), nullValue());

  // username
  NestedAttributesMap httpclient = repository.getConfiguration().attributes("httpclient").child("authentication");
  httpclient.set("type", "username");
  httpclient.set("username", "jsmith");
  httpclient.set("password", "p4ssw0rd");

  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getHttpClient().getAuthentication().getType(), is("username"));
  assertThat(proxyRepository.getHttpClient().getAuthentication().getUsername(), is("jsmith"));
  assertThat(proxyRepository.getHttpClient().getAuthentication().getPassword(), nullValue());
  assertThat(proxyRepository.getHttpClient().getAuthentication().getNtlmDomain(), nullValue());
  assertThat(proxyRepository.getHttpClient().getAuthentication().getNtlmHost(), nullValue());

  // ntlm
  httpclient.set("type", "ntlm");
  httpclient.set("username", "jsmith");
  httpclient.set("password", "p4ssw0rd");
  httpclient.set("ntlmDomain", "sona");
  httpclient.set("ntlmHost", "sonatype.com");

  proxyRepository = (SimpleApiProxyRepository) underTest.adapt(repository);
  assertThat(proxyRepository.getHttpClient().getAuthentication().getType(), is("ntlm"));
  assertThat(proxyRepository.getHttpClient().getAuthentication().getUsername(), is("jsmith"));
  assertThat(proxyRepository.getHttpClient().getAuthentication().getPassword(), nullValue());
  assertThat(proxyRepository.getHttpClient().getAuthentication().getNtlmDomain(), is("sona"));
  assertThat(proxyRepository.getHttpClient().getAuthentication().getNtlmHost(), is("sonatype.com"));
}