Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #834 from sonatype/nexus-5214-separate-http-https-…

…proxy

REVIEW: [NEXUS-5214] Make possible to configure separate general (default) HTTP proxies for http and https
  • Loading branch information...
commit 8457c9ccad443f301d9421dc006fa764c618608b 2 parents 850f1ca + 2e05af2
Jason Dillon jdillon authored
Showing with 2,583 additions and 2,040 deletions.
  1. +4 −3 nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/ServerConfiguration.java
  2. +15 −5 ...core/src/main/java/org/sonatype/nexus/client/core/subsystem/config/{HttpProxy.java → RemoteProxy.java}
  3. +10 −7 ...-core/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/JerseyServerConfiguration.java
  4. +26 −22 ...ype/nexus/client/internal/rest/jersey/subsystem/config/{JerseyHttpProxy.java → JerseyRemoteProxy.java}
  5. +0 −116 ...core/src/test/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/config/JerseyHttpProxyTest.java
  6. +139 −0 ...re/src/test/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/config/JerseyRemoteProxyTest.java
  7. +4 −2 nexus-configuration-model/pom.xml
  8. +57 −5 nexus-configuration-model/src/main/mdo/nexus.xml
  9. +45 −16 nexus-core/src/main/java/org/sonatype/nexus/apachehttpclient/Hc4ProviderBase.java
  10. +55 −25 ...sonatype/nexus/apachehttpclient/{NonProxyHostsAwareHttpRoutePlanner.java → NexusHttpRoutePlanner.java}
  11. +0 −285 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/DefaultGlobalHttpProxySettings.java
  12. +3 −3 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/DefaultNexusConfiguration.java
  13. +271 −0 ...ore/src/main/java/org/sonatype/nexus/configuration/application/DefaultRemoteProxySettingsConfiguration.java
  14. +9 −8 ...nexus/configuration/application/{GlobalHttpProxySettings.java → RemoteProxySettingsConfiguration.java}
  15. +10 −14 .../events/{GlobalHttpProxySettingsChangedEvent.java → RemoteProxySettingsConfigurationChangedEvent.java}
  16. +6 −6 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/upgrade/Upgrade200to220.java
  17. +115 −0 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/upgrade/Upgrade220to250.java
  18. +20 −12 ...on/model/{CGlobalHttpProxySettingsCoreConfiguration.java → CRemoteProxySettingsCoreConfiguration.java}
  19. +16 −15 nexus-core/src/main/java/org/sonatype/nexus/configuration/model/DefaultConfigurationHelper.java
  20. +5 −3 nexus-core/src/main/java/org/sonatype/nexus/configuration/source/AbstractApplicationConfigurationSource.java
  21. +12 −3 ...core/src/main/java/org/sonatype/nexus/configuration/validator/DefaultApplicationConfigurationValidator.java
  22. +47 −36 nexus-core/src/main/java/org/sonatype/nexus/error/reporting/SetProxyPropertiesInspector.java
  23. +0 −20 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/AbstractProxyRepository.java
  24. +2 −40 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/AbstractProxyRepositoryConfigurator.java
  25. +0 −28 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/DefaultProxySelector.java
  26. +67 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/DefaultRemoteHttpProxySettings.java
  27. +22 −42 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/DefaultRemoteProxySettings.java
  28. +0 −26 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/ProxyRepository.java
  29. +0 −18 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/ProxySelector.java
  30. +58 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/RemoteHttpProxySettings.java
  31. +34 −17 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/RemoteProxySettings.java
  32. +1 −38 nexus-core/src/main/java/org/sonatype/nexus/proxy/storage/remote/DefaultRemoteStorageContext.java
  33. +2 −1  nexus-core/src/main/java/org/sonatype/nexus/proxy/storage/remote/RemoteStorageContext.java
  34. +72 −65 nexus-core/src/main/java/org/sonatype/nexus/proxy/storage/remote/commonshttpclient/HttpClientProxyUtil.java
  35. +1 −1  nexus-core/src/test/filtered-resources/META-INF/nexus/nexus.xml
  36. +1 −1  ...t/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/103-1/nexus-103.xml.result
  37. +1 −1  ...t/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/103-2/nexus-103.xml.result
  38. +7 −5 .../test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-001-1.xml.result
  39. +11 −9 .../test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-001-2.xml.result
  40. +7 −5 .../test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-001-3.xml.result
  41. +7 −5 ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-100.xml.result
  42. +1 −1  ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-101.xml.result
  43. +1 −1  ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-104.xml.result
  44. +1 −1  ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-105.xml.result
  45. +1 −1  ...urces → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-108-with-mirrors.xml.result
  46. +1 −1  ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-108.xml.result
  47. +1 −1  ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-142.xml.result
  48. +1 −1  ...rc/test/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus-143.xml.result
  49. +164 −0 nexus-core/src/test/filtered-resources/org/sonatype/nexus/configuration/upgrade/nexus-220.xml.result
  50. +1 −1  ...t/{resources → filtered-resources}/org/sonatype/nexus/configuration/upgrade/nexus1710/nexus.xml.result
  51. +25 −14 nexus-core/src/test/java/org/sonatype/nexus/configuration/ClearPasswordTest.java
  52. +42 −17 nexus-core/src/test/java/org/sonatype/nexus/configuration/application/DefaultNexusConfigurationTest.java
  53. +18 −12 ...plication/{DefaultGlobalHttpProxySettingsTest.java → DefaultRemoteProxySettingsConfigurationTest.java}
  54. +42 −26 .../java/org/sonatype/nexus/configuration/application/upgrade/DefaultApplicationConfigurationUpgraderTest.java
  55. +52 −29 nexus-core/src/test/java/org/sonatype/nexus/error/reporting/SetProxyPropertiesInspectorTest.java
  56. +29 −12 nexus-core/src/test/java/org/sonatype/nexus/proxy/NonProxyHostsTest.java
  57. +7 −21 nexus-core/src/test/java/org/sonatype/nexus/proxy/RemoteStorageSettingsInheritanceTest.java
  58. +1 −9 nexus-core/src/test/java/org/sonatype/nexus/proxy/repository/AbstractProxyRepositoryConfiguratorTest.java
  59. +6 −31 ...s-core/src/test/java/org/sonatype/nexus/proxy/storage/remote/commonshttpclient/HttpClientProxyUtilTest.java
  60. +1 −0  nexus-core/src/test/java/org/sonatype/nexus/proxy/storage/remote/httpclient/HttpClientManagerTest.java
  61. +166 −0 nexus-core/src/test/resources/org/sonatype/nexus/configuration/upgrade/nexus-220.xml
  62. +1 −1  nexus-oss-edition/src/main/filtered-resources/META-INF/nexus/nexus.xml
  63. +1 −0  nexus-test/nexus-core-testsuite/src/test/filtered-resources/logback-test.xml
  64. BIN  nexus-test/nexus-core-testsuite/src/test/it-resources/trustStore
  65. +320 −0 nexus-test/nexus-core-testsuite/src/test/java/core/webproxy/HttpAndHttpsProxyIT.java
  66. +89 −0 nexus-test/nexus-core-testsuite/src/test/java/core/webproxy/ProxyServerWithHttpsTunneling.java
  67. +0 −18 nexus-test/nexus-test-harness-its/resources/nexus1146/files/pom.xml
  68. +0 −172 nexus-test/nexus-test-harness-its/resources/nexus1146/test-config/nexus.xml
  69. +0 −18 nexus-test/nexus-test-harness-its/resources/nexus1155/files/pom.xml
  70. +0 −176 nexus-test/nexus-test-harness-its/resources/nexus1155/test-config/nexus.xml
  71. +27 −23 ...s-test-harness-its/src/test/java/org/sonatype/nexus/integrationtests/nexus1506/Nexus1506NonProxyHostIT.java
  72. +0 −96 ...ts/src/test/java/org/sonatype/nexus/integrationtests/webproxy/nexus1146/Nexus1146RepositoryOverProxyIT.java
  73. +0 −43 ...rg/sonatype/nexus/integrationtests/webproxy/nexus1155/Nexus1155RepositoryOverProxyWithAuthenticationIT.java
  74. +18 −8 ...s-lvo-plugin/src/test/java/org/sonatype/nexus/plugins/lvo/strategy/AbstractRemoteDiscoveryStrategyTest.java
  75. +140 −16 plugins/nexus-ui-extjs3-plugin/src/main/resources/static/js/Sonatype/repoServer/ServerEditPanel.js
  76. +22 −20 plugins/nexus-ui-extjs3-plugin/src/main/resources/static/js/Sonatype/repoServer/referenceData.js
  77. +1 −95 plugins/nexus-ui-extjs3-plugin/src/main/resources/static/js/repoServer/RepoEditPanel.js
  78. +45 −24 plugins/restlet1x/nexus-restlet1x-model/src/main/mdo/vos.xml
  79. +95 −21 ...estlet1x-plugin/src/main/java/org/sonatype/nexus/rest/global/AbstractGlobalConfigurationPlexusResource.java
  80. +74 −74 .../nexus-restlet1x-plugin/src/main/java/org/sonatype/nexus/rest/global/GlobalConfigurationPlexusResource.java
  81. +0 −35 ...s-restlet1x-plugin/src/main/java/org/sonatype/nexus/rest/repositories/AbstractRepositoryPlexusResource.java
  82. +0 −4 ...nexus-restlet1x-plugin/src/main/java/org/sonatype/nexus/rest/repositories/RepositoryListPlexusResource.java
  83. +0 −26 ...t1x/nexus-restlet1x-plugin/src/main/java/org/sonatype/nexus/rest/repositories/RepositoryPlexusResource.java
  84. +26 −24 ...ns/restlet1x/nexus-restlet1x-plugin/src/test/java/org/sonatype/nexus/client/model/TestMarshalUnmarchal.java
  85. +0 −59 ...x/nexus-restlet1x-plugin/src/test/java/org/sonatype/nexus/rest/repositories/RepositoryCreateUpdateTest.java
  86. +1 −0  pom.xml
7 nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/ServerConfiguration.java
View
@@ -12,7 +12,7 @@
*/
package org.sonatype.nexus.client.core.subsystem;
-import org.sonatype.nexus.client.core.subsystem.config.HttpProxy;
+import org.sonatype.nexus.client.core.subsystem.config.RemoteProxy;
/**
* Server configuration subsystem.
@@ -23,8 +23,9 @@
{
/**
- * @return Http Proxy configuration segment.
+ * @return Remote Proxy configuration segment.
+ * @since 2.5
*/
- HttpProxy proxySettings();
+ RemoteProxy remoteProxySettings();
}
20 ...nexus/client/core/subsystem/config/HttpProxy.java → ...xus/client/core/subsystem/config/RemoteProxy.java
View
@@ -12,15 +12,25 @@
*/
package org.sonatype.nexus.client.core.subsystem.config;
-import org.sonatype.nexus.rest.model.RemoteHttpProxySettings;
+import org.sonatype.nexus.rest.model.RemoteProxySettingsDTO;
/**
- * Http Proxy configuration segment.
+ * Remote Proxy configuration segment.
*
- * @since 2.2
+ * @since 2.5
*/
-public interface HttpProxy
- extends OptionalSegment<HttpProxy, RemoteHttpProxySettings>
+public interface RemoteProxy
+ extends Segment<RemoteProxy, RemoteProxySettingsDTO>
{
+ /**
+ * Disables http proxy.
+ */
+ RemoteProxy disableHttpProxy();
+
+ /**
+ * Disables https proxy.
+ */
+ RemoteProxy disableHttpsProxy();
+
}
17 ...re/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/JerseyServerConfiguration.java
View
@@ -14,8 +14,8 @@
import org.sonatype.nexus.client.core.spi.SubsystemSupport;
import org.sonatype.nexus.client.core.subsystem.ServerConfiguration;
-import org.sonatype.nexus.client.core.subsystem.config.HttpProxy;
-import org.sonatype.nexus.client.internal.rest.jersey.subsystem.config.JerseyHttpProxy;
+import org.sonatype.nexus.client.core.subsystem.config.RemoteProxy;
+import org.sonatype.nexus.client.internal.rest.jersey.subsystem.config.JerseyRemoteProxy;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
/**
@@ -30,21 +30,24 @@
* Http Proxy configuration segment.
* Lazy initialized on first request.
*/
- private HttpProxy httpProxy;
+ private RemoteProxy remoteProxy;
public JerseyServerConfiguration( final JerseyNexusClient nexusClient )
{
super( nexusClient );
}
+ /**
+ * @since 2.5
+ */
@Override
- public HttpProxy proxySettings()
+ public RemoteProxy remoteProxySettings()
{
- if ( httpProxy == null )
+ if ( remoteProxy == null )
{
- httpProxy = new JerseyHttpProxy( getNexusClient() );
+ remoteProxy = new JerseyRemoteProxy( getNexusClient() );
}
- return httpProxy;
+ return remoteProxy;
}
}
48 ...rest/jersey/subsystem/config/JerseyHttpProxy.java → ...st/jersey/subsystem/config/JerseyRemoteProxy.java
View
@@ -12,51 +12,55 @@
*/
package org.sonatype.nexus.client.internal.rest.jersey.subsystem.config;
-import org.sonatype.nexus.client.core.subsystem.config.HttpProxy;
+import org.sonatype.nexus.client.core.subsystem.config.RemoteProxy;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
import org.sonatype.nexus.rest.model.GlobalConfigurationResource;
-import org.sonatype.nexus.rest.model.RemoteHttpProxySettings;
+import org.sonatype.nexus.rest.model.RemoteProxySettingsDTO;
-public class JerseyHttpProxy
- extends JerseyOptionalSegmentSupport<HttpProxy, RemoteHttpProxySettings>
- implements HttpProxy
+/**
+ * @since 2.5
+ */
+public class JerseyRemoteProxy
+ extends JerseySegmentSupport<RemoteProxy, RemoteProxySettingsDTO>
+ implements RemoteProxy
{
- public JerseyHttpProxy( final JerseyNexusClient nexusClient )
+ public JerseyRemoteProxy( final JerseyNexusClient nexusClient )
{
super( nexusClient );
}
@Override
- protected void onDisable( final RemoteHttpProxySettings settings )
+ protected RemoteProxySettingsDTO getSettingsFrom( final GlobalConfigurationResource configuration )
{
- settings.setProxyHostname( null );
+ return configuration.getRemoteProxySettings();
}
@Override
- protected RemoteHttpProxySettings getSettingsFrom( final GlobalConfigurationResource configuration )
+ protected void setSettingsIn( final RemoteProxySettingsDTO settings,
+ final GlobalConfigurationResource configuration )
{
- return configuration.getGlobalHttpProxySettings();
+ configuration.setRemoteProxySettings( settings );
}
@Override
- protected void setSettingsIn( final RemoteHttpProxySettings settings,
- final GlobalConfigurationResource configuration )
+ protected RemoteProxySettingsDTO createSettings()
+ {
+ return new RemoteProxySettingsDTO();
+ }
+
+ @Override
+ public RemoteProxy disableHttpProxy()
{
- if ( settings.getProxyHostname() == null )
- {
- configuration.setGlobalHttpProxySettings( null );
- }
- else
- {
- configuration.setGlobalHttpProxySettings( settings );
- }
+ settings().setHttpProxySettings( null );
+ return me();
}
@Override
- protected RemoteHttpProxySettings createSettings()
+ public RemoteProxy disableHttpsProxy()
{
- return new RemoteHttpProxySettings();
+ settings().setHttpsProxySettings( null );
+ return me();
}
}
116 ...e/src/test/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/config/JerseyHttpProxyTest.java
View
@@ -1,116 +0,0 @@
-/*
- * Sonatype Nexus (TM) Open Source Version
- * Copyright (c) 2007-2013 Sonatype, Inc.
- * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
- *
- * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
- * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
- * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
- * Eclipse Foundation. All other trademarks are the property of their respective owners.
- */
-package org.sonatype.nexus.client.internal.rest.jersey.subsystem.config;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Mockito.mock;
-
-import org.junit.Test;
-import org.sonatype.nexus.client.core.subsystem.config.HttpProxy;
-import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
-import org.sonatype.nexus.rest.model.GlobalConfigurationResource;
-import org.sonatype.nexus.rest.model.RemoteHttpProxySettings;
-import org.sonatype.sisu.litmus.testsupport.TestSupport;
-
-public class JerseyHttpProxyTest
- extends TestSupport
-{
-
- private GlobalConfigurationResource configuration = new GlobalConfigurationResource();
-
- @Test
- public void noSettings()
- {
- final HttpProxy underTest = createJerseyHttpProxy();
- final RemoteHttpProxySettings settings = underTest.settings();
-
- assertThat( settings, is( notNullValue() ) );
-
- settings.setProxyHostname( "bar" );
- underTest.save();
-
- assertThat( configuration.getGlobalHttpProxySettings(), is( notNullValue() ) );
- assertThat( configuration.getGlobalHttpProxySettings().getProxyHostname(), is( "bar" ) );
- }
-
- @Test
- public void existingSettings()
- {
- final RemoteHttpProxySettings configSettings = new RemoteHttpProxySettings();
- configSettings.setProxyHostname( "foo" );
- configuration.setGlobalHttpProxySettings( configSettings );
-
- final HttpProxy underTest = createJerseyHttpProxy();
- final RemoteHttpProxySettings settings = underTest.settings();
-
- assertThat( settings, is( notNullValue() ) );
- assertThat( settings.getProxyHostname(), is( "foo" ) );
-
- settings.setProxyHostname( "bar" );
- underTest.save();
-
- assertThat( configuration.getGlobalHttpProxySettings(), is( notNullValue() ) );
- assertThat( configuration.getGlobalHttpProxySettings().getProxyHostname(), is( "bar" ) );
- }
-
- @Test
- public void reset()
- {
- final HttpProxy underTest = createJerseyHttpProxy();
- final RemoteHttpProxySettings settings = underTest.settings();
-
- assertThat( settings, is( notNullValue() ) );
-
- settings.setProxyHostname( "bar" );
- underTest.refresh();
-
- assertThat( settings.getProxyHostname(), is( nullValue() ) );
- }
-
- @Test
- public void disable()
- {
- final RemoteHttpProxySettings configSettings = new RemoteHttpProxySettings();
- configSettings.setProxyHostname( "foo" );
- configuration.setGlobalHttpProxySettings( configSettings );
-
- final HttpProxy underTest = createJerseyHttpProxy();
-
- underTest.disable();
-
- assertThat( configuration.getGlobalHttpProxySettings(), is( nullValue() ) );
- }
-
- private JerseyHttpProxy createJerseyHttpProxy()
- {
- return new JerseyHttpProxy( mock( JerseyNexusClient.class ) )
- {
- @Override
- GlobalConfigurationResource getConfiguration()
- {
- return configuration;
- }
-
- @Override
- void setConfiguration( final GlobalConfigurationResource configuration )
- {
- // do nothing
- }
-
- };
- }
-
-}
139 ...src/test/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/config/JerseyRemoteProxyTest.java
View
@@ -0,0 +1,139 @@
+/*
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2013 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.config;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.sonatype.nexus.client.core.subsystem.config.RemoteProxy;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.GlobalConfigurationResource;
+import org.sonatype.nexus.rest.model.RemoteHttpProxySettingsDTO;
+import org.sonatype.nexus.rest.model.RemoteProxySettingsDTO;
+import org.sonatype.sisu.litmus.testsupport.TestSupport;
+
+/**
+ * @since 2.5
+ */
+public class JerseyRemoteProxyTest
+ extends TestSupport
+{
+
+ private GlobalConfigurationResource configuration = new GlobalConfigurationResource();
+
+ @Test
+ public void noSettings()
+ {
+ final RemoteProxy underTest = createJerseyHttpProxy();
+ final RemoteProxySettingsDTO settings = underTest.settings();
+
+ assertThat( settings, is( notNullValue() ) );
+
+ settings.setHttpProxySettings( new RemoteHttpProxySettingsDTO() );
+ settings.getHttpProxySettings().setProxyHostname( "bar" );
+
+ settings.setHttpsProxySettings( new RemoteHttpProxySettingsDTO() );
+ settings.getHttpsProxySettings().setProxyHostname( "car" );
+
+ settings.addNonProxyHost( "foo" );
+
+ underTest.save();
+
+ assertThat( configuration.getRemoteProxySettings(), is( notNullValue() ) );
+
+ assertThat( configuration.getRemoteProxySettings().getHttpProxySettings(), is( notNullValue() ) );
+ assertThat( configuration.getRemoteProxySettings().getHttpProxySettings().getProxyHostname(), is( "bar" ) );
+
+ assertThat( configuration.getRemoteProxySettings().getHttpsProxySettings(), is( notNullValue() ) );
+ assertThat( configuration.getRemoteProxySettings().getHttpsProxySettings().getProxyHostname(), is( "car" ) );
+
+ assertThat( configuration.getRemoteProxySettings().getNonProxyHosts(), hasItem( "foo" ) );
+ }
+
+ @Test
+ public void existingSettings()
+ {
+ final RemoteProxySettingsDTO configSettings = new RemoteProxySettingsDTO();
+ configSettings.setHttpProxySettings( new RemoteHttpProxySettingsDTO() );
+ configSettings.getHttpProxySettings().setProxyHostname( "foo" );
+ configSettings.setHttpsProxySettings( new RemoteHttpProxySettingsDTO() );
+ configSettings.getHttpsProxySettings().setProxyHostname( "bar" );
+ configSettings.addNonProxyHost( "car1" );
+ configuration.setRemoteProxySettings( configSettings );
+
+ final RemoteProxy underTest = createJerseyHttpProxy();
+ final RemoteProxySettingsDTO settings = underTest.settings();
+
+ assertThat( settings, is( notNullValue() ) );
+ assertThat( settings.getHttpProxySettings(), is( notNullValue() ) );
+ assertThat( settings.getHttpProxySettings().getProxyHostname(), is( "foo" ) );
+ assertThat( settings.getHttpsProxySettings(), is( notNullValue() ) );
+ assertThat( settings.getHttpsProxySettings().getProxyHostname(), is( "bar" ) );
+ assertThat( settings.getNonProxyHosts(), hasItem( "car1" ) );
+
+ configSettings.getHttpProxySettings().setProxyHostname( "foo1" );
+ configSettings.getHttpsProxySettings().setProxyHostname( "bar1" );
+ configSettings.addNonProxyHost( "car2" );
+ underTest.save();
+
+ assertThat( configuration.getRemoteProxySettings(), is( notNullValue() ) );
+
+ assertThat( configuration.getRemoteProxySettings().getHttpProxySettings(), is( notNullValue() ) );
+ assertThat( configuration.getRemoteProxySettings().getHttpProxySettings().getProxyHostname(), is( "foo1" ) );
+
+ assertThat( configuration.getRemoteProxySettings().getHttpsProxySettings(), is( notNullValue() ) );
+ assertThat( configuration.getRemoteProxySettings().getHttpsProxySettings().getProxyHostname(), is( "bar1" ) );
+
+ assertThat( configuration.getRemoteProxySettings().getNonProxyHosts(), hasItem( "car1" ) );
+ assertThat( configuration.getRemoteProxySettings().getNonProxyHosts(), hasItem( "car2" ) );
+ }
+
+ @Test
+ public void reset()
+ {
+ final RemoteProxy underTest = createJerseyHttpProxy();
+ final RemoteProxySettingsDTO settings = underTest.settings();
+
+ assertThat( settings, is( notNullValue() ) );
+
+ settings.addNonProxyHost( "bar" );
+ underTest.refresh();
+
+ assertThat( settings.getNonProxyHosts(), not( hasItem( "bar" ) ) );
+ }
+
+ private JerseyRemoteProxy createJerseyHttpProxy()
+ {
+ return new JerseyRemoteProxy( mock( JerseyNexusClient.class ) )
+ {
+ @Override
+ GlobalConfigurationResource getConfiguration()
+ {
+ return configuration;
+ }
+
+ @Override
+ void setConfiguration( final GlobalConfigurationResource configuration )
+ {
+ // do nothing
+ }
+
+ };
+ }
+
+}
6 nexus-configuration-model/pom.xml
View
@@ -60,7 +60,7 @@
</goals>
<configuration>
<useJava5>true</useJava5>
- <version>2.2.0</version>
+ <version>2.5.0</version>
<packagedVersions>
<packagedVersion>1.4.0</packagedVersion>
<packagedVersion>1.4.1</packagedVersion>
@@ -71,6 +71,7 @@
<packagedVersion>1.4.6</packagedVersion>
<packagedVersion>1.10.0</packagedVersion>
<packagedVersion>2.0.0</packagedVersion>
+ <packagedVersion>2.2.0</packagedVersion>
</packagedVersions>
<models>
<model>src/main/mdo/nexus.xml</model>
@@ -118,7 +119,7 @@
</goals>
<phase>generate-sources</phase>
<configuration>
- <version>2.2.0</version>
+ <version>2.5.0</version>
<packagedVersions>
<packagedVersion>1.4.0</packagedVersion>
<packagedVersion>1.4.1</packagedVersion>
@@ -129,6 +130,7 @@
<packagedVersion>1.4.6</packagedVersion>
<packagedVersion>1.10.0</packagedVersion>
<packagedVersion>2.0.0</packagedVersion>
+ <packagedVersion>2.2.0</packagedVersion>
</packagedVersions>
<models>
<model>src/main/mdo/nexus.xml</model>
62 nexus-configuration-model/src/main/mdo/nexus.xml
View
@@ -73,7 +73,7 @@
</field>
<field>
<name>globalHttpProxySettings</name>
- <version>1.4.0+</version>
+ <version>1.4.0/2.2.0</version>
<description>
The global HTTP Proxy settings are settings applied across Nexus. These can be overridden by
per-repository HTTP Proxy
@@ -84,6 +84,15 @@
<required>false</required>
</field>
<field>
+ <name>remoteProxySettings</name>
+ <version>2.5.0+</version>
+ <description>The global Remote Proxy settings are settings applied across Nexus.</description>
+ <association>
+ <type>CRemoteProxySettings</type>
+ </association>
+ <required>false</required>
+ </field>
+ <field>
<name>restApi</name>
<version>1.4.0+</version>
<description>The Nexus REST settings.</description>
@@ -258,6 +267,12 @@
public static final String MODEL_VERSION = "2.2.0";
]]></code>
</codeSegment>
+ <codeSegment>
+ <version>2.5.0</version>
+ <code><![CDATA[
+ public static final String MODEL_VERSION = "2.5.0";
+]]></code>
+ </codeSegment>
</codeSegments>
</class>
@@ -298,13 +313,50 @@
</class>
<class>
+ <name>CRemoteProxySettings</name>
+ <version>2.5.0+</version>
+ <description>The HTTP Proxy defines proxies used to access the internet.</description>
+ <fields>
+ <field>
+ <name>httpProxySettings</name>
+ <version>2.5.0+</version>
+ <description>The global HTTP Proxy settings are settings applied across Nexus.</description>
+ <association>
+ <type>CRemoteHttpProxySettings</type>
+ </association>
+ <required>false</required>
+ </field>
+ <field>
+ <name>httpsProxySettings</name>
+ <version>2.5.0+</version>
+ <description>The global HTTPS Proxy settings are settings applied across Nexus.</description>
+ <association>
+ <type>CRemoteHttpProxySettings</type>
+ </association>
+ <required>false</required>
+ </field>
+ <field>
+ <name>nonProxyHosts</name>
+ <version>2.5.0+</version>
+ <description>
+ List of addresses that can ignore the proxy settings.</description>
+ <association>
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <required>false</required>
+ </field>
+ </fields>
+ </class>
+
+ <class>
<name>CRemoteHttpProxySettings</name>
<version>1.4.0+</version>
<description>The HTTP Proxy defines proxies used to access the internet.</description>
<fields>
<field>
<name>blockInheritance</name>
- <version>1.4.0+</version>
+ <version>1.4.0/2.2.0</version>
<type>boolean</type>
<description>Set to true if you want to block inheritance.</description>
<required>true</required>
@@ -333,7 +385,7 @@
</field>
<field>
<name>nonProxyHosts</name>
- <version>1.4.1+</version>
+ <version>1.4.1/2.2.0</version>
<description>
List of addresses that can ignore the proxy settings.</description>
<association>
@@ -759,14 +811,14 @@
</field>
<field>
<name>inheritHttpProxySettings</name>
- <version>1.4.0+</version>
+ <version>1.4.0/2.2.0</version>
<type>boolean</type>
<description>Should this remote storage inherit the global settings? If true, it will inherit, if false, the proxy defined or none will be used.</description>
<required>true</required>
</field>
<field>
<name>httpProxySettings</name>
- <version>1.4.0+</version>
+ <version>1.4.0/2.2.0</version>
<description>
The specific HTTP Proxy settings to use when connecting to this repository.
</description>
61 nexus-core/src/main/java/org/sonatype/nexus/apachehttpclient/Hc4ProviderBase.java
View
@@ -13,6 +13,7 @@
package org.sonatype.nexus.apachehttpclient;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
@@ -22,6 +23,7 @@
import javax.inject.Singleton;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.http.HttpHost;
import org.apache.http.HttpVersion;
@@ -33,7 +35,6 @@
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.params.HttpConnectionParams;
@@ -214,21 +215,50 @@ else if ( ras instanceof UsernamePasswordRemoteAuthenticationSettings )
}
}
- protected void configureProxy( final DefaultHttpClient httpClient, final RemoteProxySettings remoteProxySettings )
+ /**
+ * @since 2.5
+ */
+ protected void configureProxy( final DefaultHttpClient httpClient,
+ final RemoteProxySettings remoteProxySettings)
{
- if ( remoteProxySettings.isEnabled() )
+ if ( remoteProxySettings != null
+ && remoteProxySettings.getHttpProxySettings() != null
+ && remoteProxySettings.getHttpProxySettings().isEnabled() )
{
- getLogger().debug("proxy setup with host '{}'", remoteProxySettings.getHostname());
+ final Map<String, HttpHost> proxies = Maps.newHashMap();
- final HttpHost proxy = new HttpHost( remoteProxySettings.getHostname(), remoteProxySettings.getPort() );
- httpClient.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy );
+ final HttpHost httpProxy = new HttpHost(
+ remoteProxySettings.getHttpProxySettings().getHostname(),
+ remoteProxySettings.getHttpProxySettings().getPort()
+ );
+ configureAuthentication(
+ httpClient, remoteProxySettings.getHttpProxySettings().getProxyAuthentication(), httpProxy
+ );
- // check if we have non-proxy hosts
- if ( remoteProxySettings.getNonProxyHosts() != null && !remoteProxySettings.getNonProxyHosts().isEmpty() )
+ getLogger().debug(
+ "http proxy setup with host '{}'", remoteProxySettings.getHttpProxySettings().getHostname()
+ );
+ proxies.put( "http", httpProxy );
+
+ if ( remoteProxySettings.getHttpsProxySettings() != null
+ && remoteProxySettings.getHttpsProxySettings().isEnabled() )
{
- final Set<Pattern> nonProxyHostPatterns = Sets.newHashSetWithExpectedSize(
- remoteProxySettings.getNonProxyHosts().size()
+ final HttpHost httpsProxy = new HttpHost(
+ remoteProxySettings.getHttpsProxySettings().getHostname(),
+ remoteProxySettings.getHttpsProxySettings().getPort()
+ );
+ configureAuthentication(
+ httpClient, remoteProxySettings.getHttpsProxySettings().getProxyAuthentication(), httpsProxy
+ );
+ getLogger().debug(
+ "https proxy setup with host '{}'", remoteProxySettings.getHttpsProxySettings().getHostname()
);
+ proxies.put( "https", httpsProxy );
+ }
+
+ final Set<Pattern> nonProxyHostPatterns = Sets.newHashSet();
+ if ( remoteProxySettings.getNonProxyHosts() != null && !remoteProxySettings.getNonProxyHosts().isEmpty() )
+ {
for ( String nonProxyHostRegex : remoteProxySettings.getNonProxyHosts() )
{
try
@@ -240,14 +270,13 @@ protected void configureProxy( final DefaultHttpClient httpClient, final RemoteP
getLogger().warn( "Invalid non proxy host regex: {}", nonProxyHostRegex, e );
}
}
- httpClient.setRoutePlanner(
- new NonProxyHostsAwareHttpRoutePlanner(
- httpClient.getConnectionManager().getSchemeRegistry(), nonProxyHostPatterns
- )
- );
}
- configureAuthentication( httpClient, remoteProxySettings.getProxyAuthentication(), proxy );
+ httpClient.setRoutePlanner(
+ new NexusHttpRoutePlanner(
+ proxies, httpClient.getConnectionManager().getSchemeRegistry(), nonProxyHostPatterns
+ )
+ );
}
}
80 ...ttpclient/NonProxyHostsAwareHttpRoutePlanner.java → ...nexus/apachehttpclient/NexusHttpRoutePlanner.java
View
@@ -12,6 +12,9 @@
*/
package org.sonatype.nexus.apachehttpclient;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
@@ -26,14 +29,14 @@
import org.apache.http.impl.conn.DefaultHttpRoutePlanner;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
-import com.google.common.base.Preconditions;
/**
- * An {@link HttpRoutePlanner} that bypasses proxy for specific hosts.
- *
- * @since 2.2
+ * An {@link HttpRoutePlanner} that uses different proxies / url scheme (http/https) and bypasses proxy for specific
+ * hosts (non proxy hosts).
+ *
+ * @since 2.5
*/
-class NonProxyHostsAwareHttpRoutePlanner
+class NexusHttpRoutePlanner
extends DefaultHttpRoutePlanner
{
@@ -46,14 +49,25 @@
*/
private final Set<Pattern> nonProxyHostPatterns;
+ /**
+ * Mapping between protocol scheme and proxy to be used
+ */
+ private final Map<String, HttpHost> proxies;
+
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
- NonProxyHostsAwareHttpRoutePlanner( final SchemeRegistry schemeRegistry, final Set<Pattern> nonProxyHostPatterns )
+ /**
+ * @since 2.5
+ */
+ NexusHttpRoutePlanner( final Map<String, HttpHost> proxies,
+ final SchemeRegistry schemeRegistry,
+ final Set<Pattern> nonProxyHostPatterns )
{
super( schemeRegistry );
- this.nonProxyHostPatterns = Preconditions.checkNotNull( nonProxyHostPatterns );
+ this.proxies = checkNotNull( proxies );
+ this.nonProxyHostPatterns = checkNotNull( nonProxyHostPatterns );
}
// ----------------------------------------------------------------------
@@ -63,14 +77,28 @@
public HttpRoute determineRoute( final HttpHost target, final HttpRequest request, final HttpContext context )
throws HttpException
{
- if ( request.getParams() instanceof ClientParamsStack )
- {
- request.setParams( new NonProxyHostParamsStack( (ClientParamsStack) request.getParams(),
- noProxyFor( target.getHostName() ) ) );
- }
- else
+ final HttpHost proxy = proxies.get( target.getSchemeName() );
+
+ if ( proxy != null )
{
- request.setParams( new NonProxyHostParamsStack( request.getParams(), noProxyFor( target.getHostName() ) ) );
+ if ( request.getParams() instanceof ClientParamsStack )
+ {
+ request.setParams(
+ new NonProxyHostParamsStack(
+ (ClientParamsStack) request.getParams(),
+ noProxyFor( target.getHostName() ) ? null : proxy
+ )
+ );
+ }
+ else
+ {
+ request.setParams(
+ new NonProxyHostParamsStack(
+ request.getParams(),
+ noProxyFor( target.getHostName() ) ? null : proxy
+ )
+ );
+ }
}
return super.determineRoute( target, request, context );
@@ -96,35 +124,37 @@ private boolean noProxyFor( final String hostName )
extends ClientParamsStack
{
- private final boolean filterProxy;
+ private final HttpHost proxy;
/**
* @param stack the parameter stack to delegate to
- * @param filterProxy if {@code true}, always return null on
- * {@code #getParameter( ConnRouteParams.DEFAULT_PROXY )}
+ * @param proxy proxy to be returned on {@code #getParameter(ConnRouteParams.DEFAULT_PROXY)}
*/
- public NonProxyHostParamsStack( final ClientParamsStack stack, final boolean filterProxy )
+ public NonProxyHostParamsStack( final ClientParamsStack stack, final HttpHost proxy )
{
super( stack.getApplicationParams(), stack.getClientParams(), stack.getRequestParams(),
- stack.getOverrideParams() );
- this.filterProxy = filterProxy;
+ stack.getOverrideParams() );
+ this.proxy = proxy;
}
/**
* @param params the parameters instance to delegate to
- * @param filterProxy if {@code true}, always return null on
- * {@code #getParameter( ConnRouteParams.DEFAULT_PROXY )}
+ * @param @param proxy proxy to be returned on {@code #getParameter(ConnRouteParams.DEFAULT_PROXY)}
*/
- public NonProxyHostParamsStack( final HttpParams params, final boolean filterProxy )
+ public NonProxyHostParamsStack( final HttpParams params, final HttpHost proxy )
{
super( null, null, params, null );
- this.filterProxy = filterProxy;
+ this.proxy = proxy;
}
@Override
public Object getParameter( final String name )
{
- return filterProxy && ConnRouteParams.DEFAULT_PROXY.equals( name ) ? null : super.getParameter( name );
+ if ( ConnRouteParams.DEFAULT_PROXY.equals( name ) )
+ {
+ return proxy;
+ }
+ return super.getParameter( name );
}
}
}
285 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/DefaultGlobalHttpProxySettings.java
View
@@ -1,285 +0,0 @@
-/*
- * Sonatype Nexus (TM) Open Source Version
- * Copyright (c) 2007-2013 Sonatype, Inc.
- * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
- *
- * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
- * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
- * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
- * Eclipse Foundation. All other trademarks are the property of their respective owners.
- */
-package org.sonatype.nexus.configuration.application;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.sonatype.configuration.ConfigurationException;
-import org.sonatype.nexus.configuration.AbstractConfigurable;
-import org.sonatype.nexus.configuration.Configurator;
-import org.sonatype.nexus.configuration.CoreConfiguration;
-import org.sonatype.nexus.configuration.application.events.GlobalHttpProxySettingsChangedEvent;
-import org.sonatype.nexus.configuration.model.CGlobalHttpProxySettingsCoreConfiguration;
-import org.sonatype.nexus.configuration.model.CRemoteHttpProxySettings;
-import org.sonatype.nexus.proxy.repository.DefaultRemoteProxySettings;
-import org.sonatype.nexus.proxy.repository.RemoteAuthenticationSettings;
-import org.sonatype.nexus.proxy.repository.RemoteProxySettings;
-
-@Component( role = GlobalHttpProxySettings.class )
-public class DefaultGlobalHttpProxySettings
- extends AbstractConfigurable
- implements GlobalHttpProxySettings
-{
- @Requirement
- private AuthenticationInfoConverter authenticationInfoConverter;
-
- @Override
- protected ApplicationConfiguration getApplicationConfiguration()
- {
- return null;
- }
-
- @Override
- protected Configurator getConfigurator()
- {
- return null;
- }
-
- @Override
- protected CRemoteHttpProxySettings getCurrentConfiguration( boolean forWrite )
- {
- return ( (CGlobalHttpProxySettingsCoreConfiguration) getCurrentCoreConfiguration() )
- .getConfiguration( forWrite );
- }
-
- @Override
- protected CoreConfiguration wrapConfiguration( Object configuration )
- throws ConfigurationException
- {
- if ( configuration instanceof ApplicationConfiguration )
- {
- return new CGlobalHttpProxySettingsCoreConfiguration( (ApplicationConfiguration) configuration );
- }
- else
- {
- throw new ConfigurationException( "The passed configuration object is of class \""
- + configuration.getClass().getName() + "\" and not the required \""
- + ApplicationConfiguration.class.getName() + "\"!" );
- }
- }
-
- // ==
-
- public boolean isBlockInheritance()
- {
- if ( isEnabled() )
- {
- return getCurrentConfiguration( false ).isBlockInheritance();
- }
-
- return false;
- }
-
- public void setBlockInheritance( boolean val )
- {
- if ( !isEnabled() )
- {
- initConfig();
- }
-
- getCurrentConfiguration( true ).setBlockInheritance( val );
- }
-
- public String getHostname()
- {
- if ( isEnabled() )
- {
- return getCurrentConfiguration( false ).getProxyHostname();
- }
-
- return null;
- }
-
- public void setHostname( String hostname )
- {
- if ( !isEnabled() )
- {
- initConfig();
- }
-
- getCurrentConfiguration( true ).setProxyHostname( hostname );
- }
-
- public int getPort()
- {
- if ( isEnabled() )
- {
- return getCurrentConfiguration( false ).getProxyPort();
- }
-
- return -1;
- }
-
- public void setPort( int port )
- {
- if ( !isEnabled() )
- {
- initConfig();
- }
-
- getCurrentConfiguration( true ).setProxyPort( port );
- }
-
- public RemoteAuthenticationSettings getProxyAuthentication()
- {
- if ( isEnabled() )
- {
- try
- {
- return authenticationInfoConverter.convertAndValidateFromModel( getCurrentConfiguration( false )
- .getAuthentication() );
- }
- catch ( ConfigurationException e )
- {
- // FIXME: what here??
-
- setProxyAuthentication( null );
-
- return null;
- }
- }
-
- return null;
- }
-
- public void setProxyAuthentication( RemoteAuthenticationSettings proxyAuthentication )
- {
- if ( !isEnabled() )
- {
- initConfig();
- }
-
- getCurrentConfiguration( true ).setAuthentication(
- authenticationInfoConverter
- .convertToModel( proxyAuthentication ) );
- }
-
- public RemoteProxySettings convertAndValidateFromModel( CRemoteHttpProxySettings model )
- throws ConfigurationException
- {
- ( (CGlobalHttpProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).doValidateChanges( model );
-
- if ( model != null )
- {
- RemoteProxySettings remoteProxySettings = new DefaultRemoteProxySettings();
-
- remoteProxySettings.setBlockInheritance( model.isBlockInheritance() );
-
- if ( remoteProxySettings.isBlockInheritance() )
- {
- return remoteProxySettings;
- }
-
- remoteProxySettings.setHostname( model.getProxyHostname() );
-
- remoteProxySettings.setPort( model.getProxyPort() );
-
- remoteProxySettings.setProxyAuthentication( authenticationInfoConverter.convertAndValidateFromModel( model
- .getAuthentication() ) );
-
- remoteProxySettings.setNonProxyHosts( new HashSet<String>( model.getNonProxyHosts() ) );
-
- return remoteProxySettings;
- }
- else
- {
- return null;
- }
- }
-
- public CRemoteHttpProxySettings convertToModel( RemoteProxySettings settings )
- {
- if ( settings == null )
- {
- return null;
- }
- else
- {
- CRemoteHttpProxySettings model = new CRemoteHttpProxySettings();
-
- model.setBlockInheritance( settings.isBlockInheritance() );
-
- model.setProxyHostname( settings.getHostname() );
-
- model.setProxyPort( settings.getPort() );
-
- model.setAuthentication( authenticationInfoConverter.convertToModel( settings.getProxyAuthentication() ) );
-
- model.setNonProxyHosts( new ArrayList<String>(settings.getNonProxyHosts() ) );
-
- return model;
- }
- }
-
- // ==
-
- public void disable()
- {
- ( (CGlobalHttpProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).nullifyConfig();
- }
-
- public boolean isEnabled()
- {
- return getCurrentConfiguration( false ) != null;
- }
-
- protected void initConfig()
- {
- ( (CGlobalHttpProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).initConfig();
- }
-
- public String getName()
- {
- return "Global Http Proxy Settings";
- }
-
- public Set<String> getNonProxyHosts()
- {
- if ( isEnabled() )
- {
- return new HashSet<String>( getCurrentConfiguration( false ).getNonProxyHosts() );
- }
-
- return Collections.emptySet();
- }
-
- public void setNonProxyHosts( Set<String> nonProxyHosts )
- {
- if ( !isEnabled() )
- {
- initConfig();
- }
-
- getCurrentConfiguration( true ).setNonProxyHosts( new ArrayList<String>( nonProxyHosts ) );
- }
-
- @Override
- public boolean commitChanges()
- throws ConfigurationException
- {
- boolean wasDirty = super.commitChanges();
-
- if ( wasDirty )
- {
- eventBus().post( new GlobalHttpProxySettingsChangedEvent( this ) );
- }
-
- return wasDirty;
- }
-
-}
6 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/DefaultNexusConfiguration.java
View
@@ -122,7 +122,7 @@
private GlobalRemoteConnectionSettings globalRemoteConnectionSettings;
@Requirement
- private GlobalHttpProxySettings globalHttpProxySettings;
+ private RemoteProxySettingsConfiguration remoteProxySettingsConfiguration;
/**
* The config validator.
@@ -275,9 +275,9 @@ public synchronized void loadConfiguration( boolean force )
globalRemoteStorageContext.setRemoteConnectionSettings( globalRemoteConnectionSettings );
- globalHttpProxySettings.configure( this );
+ remoteProxySettingsConfiguration.configure( this );
- globalRemoteStorageContext.setRemoteProxySettings( globalHttpProxySettings );
+ globalRemoteStorageContext.setRemoteProxySettings( remoteProxySettingsConfiguration );
ConfigurationPrepareForLoadEvent loadEvent = new ConfigurationPrepareForLoadEvent( this );
271 .../src/main/java/org/sonatype/nexus/configuration/application/DefaultRemoteProxySettingsConfiguration.java
View
@@ -0,0 +1,271 @@
+/*
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2013 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.configuration.application;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.sonatype.configuration.ConfigurationException;
+import org.sonatype.nexus.configuration.AbstractConfigurable;
+import org.sonatype.nexus.configuration.Configurator;
+import org.sonatype.nexus.configuration.CoreConfiguration;
+import org.sonatype.nexus.configuration.application.events.RemoteProxySettingsConfigurationChangedEvent;
+import org.sonatype.nexus.configuration.model.CRemoteHttpProxySettings;
+import org.sonatype.nexus.configuration.model.CRemoteProxySettings;
+import org.sonatype.nexus.configuration.model.CRemoteProxySettingsCoreConfiguration;
+import org.sonatype.nexus.proxy.repository.DefaultRemoteHttpProxySettings;
+import org.sonatype.nexus.proxy.repository.DefaultRemoteProxySettings;
+import org.sonatype.nexus.proxy.repository.RemoteHttpProxySettings;
+import org.sonatype.nexus.proxy.repository.RemoteProxySettings;
+import com.google.common.base.Throwables;
+
+/**
+ * @since 2.5
+ */
+@Component( role = RemoteProxySettingsConfiguration.class )
+public class DefaultRemoteProxySettingsConfiguration
+ extends AbstractConfigurable
+ implements RemoteProxySettingsConfiguration
+{
+
+ @Requirement
+ private AuthenticationInfoConverter authenticationInfoConverter;
+
+ @Override
+ protected ApplicationConfiguration getApplicationConfiguration()
+ {
+ return null;
+ }
+
+ @Override
+ protected Configurator getConfigurator()
+ {
+ return null;
+ }
+
+ @Override
+ protected CRemoteProxySettings getCurrentConfiguration( boolean forWrite )
+ {
+ return ( (CRemoteProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).getConfiguration( forWrite );
+ }
+
+ @Override
+ protected CoreConfiguration wrapConfiguration( Object configuration )
+ throws ConfigurationException
+ {
+ if ( configuration instanceof ApplicationConfiguration )
+ {
+ return new CRemoteProxySettingsCoreConfiguration( (ApplicationConfiguration) configuration );
+ }
+ else
+ {
+ throw new ConfigurationException( "The passed configuration object is of class \""
+ + configuration.getClass().getName() + "\" and not the required \""
+ + ApplicationConfiguration.class.getName() + "\"!" );
+ }
+ }
+
+ // ==
+
+ @Override
+ public RemoteHttpProxySettings getHttpProxySettings()
+ {
+ if ( isEnabled() )
+ {
+ try
+ {
+ return convertFromModel( getCurrentConfiguration( false ).getHttpProxySettings() );
+ }
+ catch ( ConfigurationException e )
+ {
+ throw Throwables.propagate( e );
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void setHttpProxySettings( final RemoteHttpProxySettings settings )
+ {
+ if ( !isEnabled() )
+ {
+ initConfig();
+ }
+ getCurrentConfiguration( true ).setHttpProxySettings( convertToModel( settings ) );
+ }
+
+ @Override
+ public RemoteHttpProxySettings getHttpsProxySettings()
+ {
+ if ( isEnabled() )
+ {
+ try
+ {
+ return convertFromModel( getCurrentConfiguration( false ).getHttpsProxySettings() );
+ }
+ catch ( ConfigurationException e )
+ {
+ throw Throwables.propagate( e );
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void setHttpsProxySettings( final RemoteHttpProxySettings settings )
+ {
+ if ( !isEnabled() )
+ {
+ initConfig();
+ }
+ getCurrentConfiguration( true ).setHttpsProxySettings( convertToModel( settings ) );
+ }
+
+ @Override
+ public Set<String> getNonProxyHosts()
+ {
+ if ( isEnabled() )
+ {
+ return new HashSet<String>( getCurrentConfiguration( false ).getNonProxyHosts() );
+ }
+
+ return Collections.emptySet();
+ }
+
+ @Override
+ public void setNonProxyHosts( Set<String> nonProxyHosts )
+ {
+ if ( !isEnabled() )
+ {
+ initConfig();
+ }
+
+ getCurrentConfiguration( true ).setNonProxyHosts( new ArrayList<String>(
+ nonProxyHosts == null ? Collections.<String>emptySet() : nonProxyHosts
+ ) );
+ }
+
+ public RemoteProxySettings convertAndValidateFromModel( CRemoteProxySettings model )
+ throws ConfigurationException
+ {
+ ( (CRemoteProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).doValidateChanges( model );
+
+ if ( model == null )
+ {
+ return null;
+ }
+
+ final RemoteProxySettings settings = new DefaultRemoteProxySettings();
+
+ settings.setHttpProxySettings( convertFromModel( model.getHttpProxySettings() ) );
+ settings.setHttpsProxySettings( convertFromModel( model.getHttpsProxySettings() ) );
+ settings.setNonProxyHosts( new HashSet<String>( model.getNonProxyHosts() ) );
+
+ return settings;
+ }
+
+ private RemoteHttpProxySettings convertFromModel( CRemoteHttpProxySettings model )
+ throws ConfigurationException
+ {
+ if ( model == null )
+ {
+ return null;
+ }
+
+ final RemoteHttpProxySettings settings = new DefaultRemoteHttpProxySettings();
+
+ settings.setHostname( model.getProxyHostname() );
+ settings.setPort( model.getProxyPort() );
+ settings.setProxyAuthentication(
+ authenticationInfoConverter.convertAndValidateFromModel( model.getAuthentication() )
+ );
+
+ return settings;
+ }
+
+ public CRemoteProxySettings convertToModel( RemoteProxySettings settings )
+ {
+ if ( settings == null )
+ {
+ return null;
+ }
+
+ final CRemoteProxySettings model = new CRemoteProxySettings();
+
+ model.setHttpProxySettings( convertToModel( settings.getHttpProxySettings() ) );
+ model.setHttpsProxySettings( convertToModel( settings.getHttpsProxySettings() ) );
+ model.setNonProxyHosts( new ArrayList<String>( settings.getNonProxyHosts() ) );
+
+ return model;
+ }
+
+ public CRemoteHttpProxySettings convertToModel( RemoteHttpProxySettings settings )
+ {
+ if ( settings == null )
+ {
+ return null;
+ }
+
+ final CRemoteHttpProxySettings model = new CRemoteHttpProxySettings();
+
+ model.setProxyHostname( settings.getHostname() );
+ model.setProxyPort( settings.getPort() );
+ model.setAuthentication( authenticationInfoConverter.convertToModel( settings.getProxyAuthentication() ) );
+
+ return model;
+ }
+
+ // ==
+
+ public void disable()
+ {
+ ( (CRemoteProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).nullifyConfig();
+ }
+
+ public boolean isEnabled()
+ {
+ return getCurrentConfiguration( false ) != null;
+ }
+
+ protected void initConfig()
+ {
+ ( (CRemoteProxySettingsCoreConfiguration) getCurrentCoreConfiguration() ).initConfig();
+ }
+
+ @Override
+ public boolean commitChanges()
+ throws ConfigurationException
+ {
+ boolean wasDirty = super.commitChanges();
+
+ if ( wasDirty )
+ {
+ eventBus().post( new RemoteProxySettingsConfigurationChangedEvent( this ) );
+ }
+
+ return wasDirty;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "Global Remote Proxy Settings";
+ }
+
+}
17 ...guration/application/GlobalHttpProxySettings.java → ...application/RemoteProxySettingsConfiguration.java
View
@@ -14,18 +14,19 @@
import org.sonatype.configuration.ConfigurationException;
import org.sonatype.nexus.configuration.Configurable;
-import org.sonatype.nexus.configuration.model.CRemoteHttpProxySettings;
+import org.sonatype.nexus.configuration.model.CRemoteProxySettings;
import org.sonatype.nexus.proxy.repository.RemoteProxySettings;
-public interface GlobalHttpProxySettings
+/**
+ * @since 2.5
+ */
+public interface RemoteProxySettingsConfiguration
extends Configurable, RemoteProxySettings
{
- RemoteProxySettings convertAndValidateFromModel( CRemoteHttpProxySettings model )
+
+ RemoteProxySettings convertAndValidateFromModel( CRemoteProxySettings model )
throws ConfigurationException;
- CRemoteHttpProxySettings convertToModel( RemoteProxySettings settings );
-
- // ==
-
- void disable();
+ CRemoteProxySettings convertToModel( RemoteProxySettings settings );
+
}
24 ...n/events/GlobalHttpProxySettingsChangedEvent.java → ...RemoteProxySettingsConfigurationChangedEvent.java
View
@@ -12,28 +12,24 @@
*/
package org.sonatype.nexus.configuration.application.events;
-import org.sonatype.nexus.configuration.application.GlobalHttpProxySettings;
+import org.sonatype.nexus.configuration.application.RemoteProxySettingsConfiguration;
import org.sonatype.plexus.appevents.AbstractEvent;
/**
- * Event fired when global HTTP Proxy settings are changed (within configuration change). The settings carried in
- * this event will reflect the NEW values, but if you have the {@link GlobalHttpProxySettings} component, you can
+ * Event fired when global remote Proxy settings are changed (within configuration change). The settings carried in
+ * this event will reflect the NEW values, but if you have the {@link org.sonatype.nexus.configuration.application.RemoteProxySettingsConfiguration} component, you can
* query it too <em>after</em> you received this event .
- *
- * @since 2.0
+ *
+ * @since 2.5
*/
-public class GlobalHttpProxySettingsChangedEvent
- extends AbstractEvent<GlobalHttpProxySettings>
+public class RemoteProxySettingsConfigurationChangedEvent
+ extends AbstractEvent<RemoteProxySettingsConfiguration>
{
- public GlobalHttpProxySettingsChangedEvent( GlobalHttpProxySettings settings )
- {
- super( settings );
- }
-
- public GlobalHttpProxySettings getGlobalHttpProxySettings()
+ public RemoteProxySettingsConfigurationChangedEvent(
+ final RemoteProxySettingsConfiguration remoteProxySettingsConfiguration )
{
- return getEventSender();
+ super( remoteProxySettingsConfiguration );
}
}
12 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/upgrade/Upgrade200to220.java
View
@@ -22,6 +22,7 @@
import org.sonatype.configuration.upgrade.ConfigurationIsCorruptedException;
import org.sonatype.configuration.upgrade.SingleVersionUpgrader;
import org.sonatype.configuration.upgrade.UpgradeMessage;
+import org.sonatype.nexus.configuration.model.v2_2_0.CRemoteStorage;
import org.sonatype.nexus.configuration.model.v2_2_0.upgrade.BasicVersionUpgrade;
import org.sonatype.nexus.logging.AbstractLoggingComponent;
@@ -77,10 +78,9 @@ public void upgrade( UpgradeMessage message )
BasicVersionUpgrade versionConverter = new BasicVersionUpgrade()
{
@Override
- public org.sonatype.nexus.configuration.model.CRemoteStorage upgradeCRemoteStorage( org.sonatype.nexus.configuration.model.v2_0_0.CRemoteStorage cRemoteStorage )
+ public CRemoteStorage upgradeCRemoteStorage( org.sonatype.nexus.configuration.model.v2_0_0.CRemoteStorage cRemoteStorage )
{
- final org.sonatype.nexus.configuration.model.CRemoteStorage remoteStorage =
- super.upgradeCRemoteStorage( cRemoteStorage );
+ final CRemoteStorage remoteStorage = super.upgradeCRemoteStorage( cRemoteStorage );
if ( remoteStorage != null )
{
if ( StringUtils.equals( remoteStorage.getProvider(), "apacheHttpClient3x" ) )
@@ -96,10 +96,10 @@ public void upgrade( UpgradeMessage message )
}
};
- org.sonatype.nexus.configuration.model.Configuration newc = versionConverter.upgradeConfiguration( oldc );
+ org.sonatype.nexus.configuration.model.v2_2_0.Configuration newc = versionConverter.upgradeConfiguration( oldc );
- newc.setVersion( org.sonatype.nexus.configuration.model.Configuration.MODEL_VERSION );
- message.setModelVersion( org.sonatype.nexus.configuration.model.Configuration.MODEL_VERSION );
+ newc.setVersion( org.sonatype.nexus.configuration.model.v2_2_0.Configuration.MODEL_VERSION );
+ message.setModelVersion( org.sonatype.nexus.configuration.model.v2_2_0.Configuration.MODEL_VERSION );
message.setConfiguration( newc );
}
}
115 nexus-core/src/main/java/org/sonatype/nexus/configuration/application/upgrade/Upgrade220to250.java
View
@@ -0,0 +1,115 @@
+/*
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2013 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.configuration.application.upgrade;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.sonatype.configuration.upgrade.ConfigurationIsCorruptedException;
+import org.sonatype.configuration.upgrade.SingleVersionUpgrader;
+import org.sonatype.configuration.upgrade.UpgradeMessage;
+import org.sonatype.nexus.configuration.model.CRemoteHttpProxySettings;
+import org.sonatype.nexus.configuration.model.CRemoteProxySettings;
+import org.sonatype.nexus.configuration.model.Configuration;
+import org.sonatype.nexus.configuration.model.v2_5_0.upgrade.BasicVersionUpgrade;
+import org.sonatype.nexus.logging.AbstractLoggingComponent;
+import com.google.common.io.Closeables;
+
+/**
+ * Upgrades configuration model from version 2.2.0 to 2.5.0.
+ *
+ * @since 2.5
+ */
+@Component(role = SingleVersionUpgrader.class, hint = "2.2.0")
+public class Upgrade220to250
+ extends AbstractLoggingComponent
+ implements SingleVersionUpgrader
+{
+
+ public Object loadConfiguration( File file )
+ throws IOException, ConfigurationIsCorruptedException
+ {
+ FileReader fr = null;
+
+ org.sonatype.nexus.configuration.model.v2_2_0.Configuration conf = null;
+
+ try
+ {
+ // reading without interpolation to preserve user settings as variables
+ fr = new FileReader( file );
+
+ org.sonatype.nexus.configuration.model.v2_2_0.io.xpp3.NexusConfigurationXpp3Reader reader =
+ new org.sonatype.nexus.configuration.model.v2_2_0.io.xpp3.NexusConfigurationXpp3Reader();
+
+ conf = reader.read( fr );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ConfigurationIsCorruptedException( file.getAbsolutePath(), e );
+ }
+ finally
+ {
+ Closeables.closeQuietly( fr );
+ }
+
+ return conf;
+ }
+
+ public void upgrade( UpgradeMessage message )
+ throws ConfigurationIsCorruptedException
+ {
+ org.sonatype.nexus.configuration.model.v2_2_0.Configuration oldc =
+ (org.sonatype.nexus.configuration.model.v2_2_0.Configuration) message.getConfiguration();
+
+ BasicVersionUpgrade versionConverter = new BasicVersionUpgrade()
+ {
+ @Override
+ public CRemoteHttpProxySettings upgradeCRemoteHttpProxySettings(
+ final org.sonatype.nexus.configuration.model.v2_2_0.CRemoteHttpProxySettings cRemoteHttpProxySettings )
+ {
+ return super.upgradeCRemoteHttpProxySettings(
+ cRemoteHttpProxySettings ); //To change body of overridden methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Configuration upgradeConfiguration(
+ final org.sonatype.nexus.configuration.model.v2_2_0.Configuration oldConfig )
+ {
+ final Configuration newConfig = super.upgradeConfiguration( oldConfig );
+
+ if ( oldConfig.getGlobalHttpProxySettings() != null )
+ {
+ newConfig.setRemoteProxySettings( new CRemoteProxySettings() );
+ newConfig.getRemoteProxySettings().setHttpProxySettings(
+ upgradeCRemoteHttpProxySettings( oldConfig.getGlobalHttpProxySettings() )
+ );
+ newConfig.getRemoteProxySettings().setNonProxyHosts(
+ oldConfig.getGlobalHttpProxySettings().getNonProxyHosts()
+ );
+ }
+
+ return newConfig;
+ }
+ };
+
+ org.sonatype.nexus.configuration.model.Configuration newc = versionConverter.upgradeConfiguration( oldc );
+
+ newc.setVersion( org.sonatype.nexus.configuration.model.Configuration.MODEL_VERSION );
+ message.setModelVersion( org.sonatype.nexus.configuration.model.Configuration.MODEL_VERSION );
+ message.setConfiguration( newc );
+ }
+
+}
32 ...el/CGlobalHttpProxySettingsCoreConfiguration.java → .../model/CRemoteProxySettingsCoreConfiguration.java
View
@@ -16,33 +16,36 @@
import org.sonatype.configuration.validation.ValidationResponse;
import org.sonatype.nexus.configuration.application.ApplicationConfiguration;
-public class CGlobalHttpProxySettingsCoreConfiguration
+/**
+ * @since 2.5
+ */
+public class CRemoteProxySettingsCoreConfiguration
extends AbstractCoreConfiguration
{
private boolean nullified;
- public CGlobalHttpProxySettingsCoreConfiguration( ApplicationConfiguration applicationConfiguration )
+ public CRemoteProxySettingsCoreConfiguration( ApplicationConfiguration applicationConfiguration )
{
super( applicationConfiguration );
}
@Override
- public CRemoteHttpProxySettings getConfiguration( boolean forWrite )
+ public CRemoteProxySettings getConfiguration( boolean forWrite )
{
- return (CRemoteHttpProxySettings) super.getConfiguration( forWrite );
+ return (CRemoteProxySettings) super.getConfiguration( forWrite );
}
@Override
- protected CRemoteHttpProxySettings extractConfiguration( Configuration configuration )
+ protected CRemoteProxySettings extractConfiguration( Configuration configuration )
{
- return configuration.getGlobalHttpProxySettings();
+ return configuration.getRemoteProxySettings();
}
public void initConfig()
{
- CRemoteHttpProxySettings newProxy = new CRemoteHttpProxySettings();
+ CRemoteProxySettings newProxy = new CRemoteProxySettings();
- getApplicationConfiguration().getConfigurationModel().setGlobalHttpProxySettings( newProxy );
+ getApplicationConfiguration().getConfigurationModel().setRemoteProxySettings( newProxy );
setOriginalConfiguration( newProxy );
}
@@ -75,7 +78,7 @@ public void commitChanges()
if ( nullified )
{
// nullified, nothing to validate and the super.commitChanges() will not work
- getApplicationConfiguration().getConfigurationModel().setGlobalHttpProxySettings( null );
+ getApplicationConfiguration().getConfigurationModel().setRemoteProxySettings( null );
}
else
{
@@ -98,11 +101,16 @@ protected void copyTransients( Object source, Object destination )
{
super.copyTransients( source, destination );
- // we need to manually set the authentication to null here, because of flawed overlay, where null objects do NOT
+ // we need to manually set the http/https to null here, because of flawed overlay, where null objects do NOT
// overwrite non-null objects
- if ( ( (CRemoteHttpProxySettings) source ).getAuthentication() == null )
+ if ( ( (CRemoteProxySettings) source ).getHttpProxySettings() == null )
+ {
+ ( (CRemoteProxySettings) destination ).setHttpProxySettings( null );
+ }
+ if ( ( (CRemoteProxySettings) source ).getHttpsProxySettings() == null )
{
- ( (CRemoteHttpProxySettings) destination ).setAuthentication( null );
+ ( (CRemoteProxySettings) destination ).setHttpsProxySettings( null );
}
}
+
}
31 nexus-core/src/main/java/org/sonatype/nexus/configuration/model/DefaultConfigurationHelper.java
View
@@ -88,12 +88,23 @@ protected void handlePasswords( final Configuration config, final boolean encryp
}
// global proxy
- if ( config.getGlobalHttpProxySettings() != null
- && config.getGlobalHttpProxySettings().getAuthentication() != null
- && StringUtils.isNotEmpty( config.getGlobalHttpProxySettings().getAuthentication().getPassword() ) )
+ final CRemoteProxySettings rps = config.getRemoteProxySettings();
+ if ( rps != null )
{
- CRemoteAuthentication auth = config.getGlobalHttpProxySettings().getAuthentication();
- auth.setPassword( encryptDecryptPassword( auth.getPassword(), encrypt, mask ) );
+ if ( rps.getHttpProxySettings() != null
+ && rps.getHttpProxySettings().getAuthentication() != null
+ && StringUtils.isNotEmpty( rps.getHttpProxySettings().getAuthentication().getPassword() ) )
+ {
+ CRemoteAuthentication auth = rps.getHttpProxySettings().getAuthentication();
+ auth.setPassword( encryptDecryptPassword( auth.getPassword(), encrypt, mask ) );
+ }
+ if ( rps.getHttpsProxySettings() != null
+ && rps.getHttpsProxySettings().getAuthentication() != null
+ && StringUtils.isNotEmpty( rps.getHttpsProxySettings().getAuthentication().getPassword() ) )
+ {
+ CRemoteAuthentication auth = rps.getHttpsProxySettings().getAuthentication();
+ auth.setPassword( encryptDecryptPassword( auth.getPassword(), encrypt, mask ) );
+ }
}
// each repo
@@ -106,16 +117,6 @@ protected void handlePasswords( final Configuration config, final boolean encryp
CRemoteAuthentication auth = repo.getRemoteStorage().getAuthentication();
auth.setPassword( encryptDecryptPassword( auth.getPassword(), encrypt, mask ) );
}
-
- // proxy auth
- if ( repo.getRemoteStorage() != null
- && repo.getRemoteStorage().getHttpProxySettings() != null
- && repo.getRemoteStorage().getHttpProxySettings().getAuthentication() != null
- && StringUtils.isNotEmpty( repo.getRemoteStorage().getHttpProxySettings().getAuthentication().getPassword() ) )
- {
- CRemoteAuthentication auth = repo.getRemoteStorage().getHttpProxySettings().getAuthentication();
- auth.setPassword( encryptDecryptPassword( auth.getPassword(), encrypt, mask ) );
- }
}
}
8 ...s-core/src/main/java/org/sonatype/nexus/configuration/source/AbstractApplicationConfigurationSource.java
View
@@ -115,10 +115,12 @@ protected void loadConfiguration( InputStream is )
// check the model version if loaded
if ( configuration != null && !Configuration.MODEL_VERSION.equals( configuration.getVersion() ) )
{
- rejectConfiguration( "Nexus configuration file was loaded but discarded, it has the wrong version number.", null );
+ final String message = "Nexus configuration file was loaded but discarded, it has the wrong version number."
+ + ( " (expected " + Configuration.MODEL_VERSION + ", actual " + configuration.getVersion() + ")");
+
+ rejectConfiguration( message , null );
- throw new ConfigurationException(
- "Nexus configuration file was loaded but discarded, it has the wrong version number." );
+ throw new ConfigurationException( message );
}
if ( getConfiguration() != null )
15 ...e/src/main/java/org/sonatype/nexus/configuration/validator/DefaultApplicationConfigurationValidator.java
View
@@ -30,6 +30,7 @@
import org.sonatype.nexus.configuration.model.CRemoteConnectionSettings;
import org.sonatype.nexus.configuration.model.CRemoteHttpProxySettings;
import org.sonatype.nexus.configuration.model.CRemoteNexusInstance;
+import org.sonatype.nexus.configuration.model.CRemoteProxySettings;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.CRepositoryGrouping;
import org.sonatype.nexus.configuration.model.CRepositoryTarget;
@@ -87,10 +88,18 @@ public ValidationResponse validateModel( ValidationRequest request )
response.setModified( true );
}
- // global httpproxy settings (optional)
- if ( model.getGlobalHttpProxySettings() != null )
+ // remote proxy settings (optional)
+ final CRemoteProxySettings rps = model.getRemoteProxySettings();
+ if ( rps != null )
{
- response.append( validateRemoteHttpProxySettings( context, model.getGlobalHttpProxySettings() ) );
+ if ( rps.getHttpProxySettings() != null )
+ {
+ response.append( validateRemoteHttpProxySettings( context, rps.getHttpProxySettings() ) );
+ }
+ if ( rps.getHttpsProxySettings() != null )
+ {
+ response.append( validateRemoteHttpProxySettings( context, rps.getHttpsProxySettings() ) );
+ }
}
// rest api
83 nexus-core/src/main/java/org/sonatype/nexus/error/reporting/SetProxyPropertiesInspector.java
View
@@ -20,15 +20,16 @@
import javax.inject.Named;
import javax.inject.Singleton;
-import com.google.common.base.Joiner;
-import org.sonatype.nexus.configuration.application.GlobalHttpProxySettings;
-import org.sonatype.nexus.configuration.application.events.GlobalHttpProxySettingsChangedEvent;
+import org.sonatype.nexus.configuration.application.RemoteProxySettingsConfiguration;
+import org.sonatype.nexus.configuration.application.events.RemoteProxySettingsConfigurationChangedEvent;
import org.sonatype.nexus.logging.AbstractLoggingComponent;
import org.sonatype.nexus.proxy.events.EventInspector;
import org.sonatype.nexus.proxy.events.NexusStartedEvent;
import org.sonatype.nexus.proxy.repository.RemoteAuthenticationSettings;
+import org.sonatype.nexus.proxy.repository.RemoteHttpProxySettings;
import org.sonatype.nexus.proxy.repository.UsernamePasswordRemoteAuthenticationSettings;
import org.sonatype.plexus.appevents.Event;
+import com.google.common.base.Joiner;
/**
* This inspector sets system properties according to the Nexus proxy settings.
@@ -41,18 +42,18 @@
implements EventInspector
{
- private final GlobalHttpProxySettings globalHttpProxySettings;
+ private final RemoteProxySettingsConfiguration remoteProxySettingsConfiguration;
@Inject
- public SetProxyPropertiesInspector( final GlobalHttpProxySettings globalHttpProxySettings )
+ public SetProxyPropertiesInspector( final RemoteProxySettingsConfiguration remoteProxySettingsConfiguration )
{
- this.globalHttpProxySettings = checkNotNull( globalHttpProxySettings );
+ this.remoteProxySettingsConfiguration = checkNotNull( remoteProxySettingsConfiguration );
}
@Override
public boolean accepts( final Event<?> evt )
{
- return evt instanceof GlobalHttpProxySettingsChangedEvent
+ return evt instanceof RemoteProxySettingsConfigurationChangedEvent
|| evt instanceof NexusStartedEvent;
}
@@ -64,45 +65,55 @@ public void inspect( final Event<?> evt )
return;
}
- if ( globalHttpProxySettings.isEnabled() )
+ if ( remoteProxySettingsConfiguration.getHttpProxySettings() != null
+ && remoteProxySettingsConfiguration.getHttpProxySettings().isEnabled() )
{
- String username = null;
- String password = null;
-
- final RemoteAuthenticationSettings authentication = globalHttpProxySettings.getProxyAuthentication();
-
- if ( authentication != null
- && UsernamePasswordRemoteAuthenticationSettings.class.isAssignableFrom( authentication.getClass() ) )
+ setProperties( remoteProxySettingsConfiguration.getHttpProxySettings(), "http" );
+ if ( remoteProxySettingsConfiguration.getHttpsProxySettings() != null
+ && remoteProxySettingsConfiguration.getHttpsProxySettings().isEnabled() )
{
- username = ( (UsernamePasswordRemoteAuthenticationSettings) authentication ).getUsername();
- password = ( (UsernamePasswordRemoteAuthenticationSettings) authentication ).getPassword();
+ setProperties( remoteProxySettingsConfiguration.getHttpsProxySettings(), "https" );
+ }
+ else
+ {
+ setProperties( remoteProxySettingsConfiguration.getHttpProxySettings(), "https" );
}
-
- final String hostname = globalHttpProxySettings.getHostname();
- final int port = globalHttpProxySettings.getPort();
- final Set<String> nonProxyHosts = globalHttpProxySettings.getNonProxyHosts();
-
- getLogger().debug(
- "Configure proxy using global http proxy settings: hostname={}, port={}, username={}, nonProxyHosts={}",
- new Object[]{ hostname, port, username, nonProxyHosts }
- );
-
- setProperties( true, hostname, port, username, password, nonProxyHosts );
}
else
{
- getLogger().debug( "No global http proxy settings. Resetting proxy properties." );
- setProperties( false, null, -1, null, null, null );
+ getLogger().debug( "No global http/https proxy settings. Resetting proxy properties." );
+
+ final Properties properties = System.getProperties();
+ setProperties( false, null, -1, null, null, null, properties, "http." );
+ setProperties( false, null, -1, null, null, null, properties, "https." );
}
}
- private void setProperties( final boolean proxiesEnabled, final String hostname, final int port,
- final String username, final String password,
- final Set<String> nonProxyHosts )
+ private void setProperties( final RemoteHttpProxySettings remoteHttpProxySettings,
+ final String scheme )
{
- Properties properties = System.getProperties();
- setProperties( proxiesEnabled, hostname, port, username, password, nonProxyHosts, properties, "http." );
- setProperties( proxiesEnabled, hostname, port, username, password, nonProxyHosts, properties, "https." );
+ String username = null;
+ String password = null;
+
+ final RemoteAuthenticationSettings authentication = remoteHttpProxySettings.getProxyAuthentication();
+
+ if ( authentication != null
+ && UsernamePasswordRemoteAuthenticationSettings.class.isAssignableFrom( authentication.getClass() ) )
+ {
+ username = ( (UsernamePasswordRemoteAuthenticationSettings) authentication ).getUsername();
+ password = ( (UsernamePasswordRemoteAuthenticationSettings) authentication ).getPassword();
+ }
+
+ final String hostname = remoteHttpProxySettings.getHostname();
+ final int port = remoteHttpProxySettings.getPort();
+ final Set<String> nonProxyHosts = remoteProxySettingsConfiguration.getNonProxyHosts();
+
+ getLogger().debug(
+ "Configure proxy using global {} proxy settings: hostname={}, port={}, username={}, nonProxyHosts={}",
+ scheme, hostname, port, username, nonProxyHosts
+ );
+
+ setProperties( true, hostname, port, username, password, nonProxyHosts, System.getProperties(), scheme + "." );
}
private void setProperties( final boolean proxiesEnabled, final String hostname, final int port,
20 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/AbstractProxyRepository.java
View
@@ -147,11 +147,6 @@
private RemoteStorageContext remoteStorageContext;
/**
- * Proxy selector, if set
- */
- private ProxySelector proxySelector;
-
- /**
* Download mirrors
*/
private DownloadMirrors dMirrors;
@@ -916,21 +911,6 @@ public void setRemoteProxySettings( RemoteProxySettings settings )
}
}
- public ProxySelector getProxySelector()
- {
- if ( proxySelector == null )
- {
- proxySelector = new DefaultProxySelector();
- }
-
- return proxySelector;
- }
-
- public void setProxySelector( ProxySelector selector )
- {
- this.proxySelector = selector;
- }
-
public RemoteRepositoryStorage getRemoteStorage()
{
return remoteStorage;
42 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/AbstractProxyRepositoryConfigurator.java
View
@@ -21,9 +21,7 @@
import org.sonatype.configuration.validation.ValidationResponse;
import org.sonatype.nexus.configuration.application.ApplicationConfiguration;
import org.sonatype.nexus.configuration.application.AuthenticationInfoConverter;
-import org.sonatype.nexus.configuration.application.GlobalHttpProxySettings;
import org.sonatype.nexus.configuration.application.GlobalRemoteConnectionSettings;
-import org.sonatype.nexus.configuration.model.CRemoteHttpProxySettings;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.CRepositoryCoreConfiguration;
import org.sonatype.nexus.configuration.validator.ApplicationValidationResponse;
@@ -42,9 +40,6 @@
private GlobalRemoteConnectionSettings globalRemoteConnectionSettings;
@Requirement
- private GlobalHttpProxySettings globalHttpProxySettings;
-
- @Requirement
private RemoteProviderHintFactory remoteProviderHintFactory;
/**
@@ -56,12 +51,10 @@ protected AbstractProxyRepositoryConfigurator()
@VisibleForTesting
AbstractProxyRepositoryConfigurator( final AuthenticationInfoConverter authenticationInfoConverter,
- final GlobalHttpProxySettings globalHttpProxySettings,
- final GlobalRemoteConnectionSettings globalRemoteConnectionSettings,
- final RemoteProviderHintFactory remoteProviderHintFactory )
+ final GlobalRemoteConnectionSettings globalRemoteConnectionSettings,
+ final RemoteProviderHintFactory remoteProviderHintFactory )
{
this.authenticationInfoConverter = authenticationInfoConverter;
- this.globalHttpProxySettings = globalHttpProxySettings;
this.globalRemoteConnectionSettings = globalRemoteConnectionSettings;
this.remoteProviderHintFactory = remoteProviderHintFactory;
}
@@ -118,18 +111,6 @@ public void doApplyConfiguration( Repository repository, ApplicationConfiguratio
{
prepository.setRemoteConnectionSettings( globalRemoteConnectionSettings.convertAndValidateFromModel( repo.getRemoteStorage().getConnectionSettings() ) );
}
-
- if ( repo.getRemoteStorage().getHttpProxySettings() != null )
- {
- if ( repo.getRemoteStorage().getHttpProxySettings().isBlockInheritance() )
- {
- prepository.setRemoteProxySettings( null );
- }
- else
- {
- prepository.setRemoteProxySettings( globalHttpProxySettings.convertAndValidateFromModel( repo.getRemoteStorage().getHttpProxySettings() ) );
- }
- }
}
else
{
@@ -193,25 +174,6 @@ protected void doPrepareForSave( Repository repository, ApplicationConfiguration
{
repoConfig.getRemoteStorage().setConnectionSettings( null );
}
-
- if ( rsc.hasRemoteProxySettings() )
- {
- if ( rsc.getRemoteProxySettings() != null )
- {
- repoConfig.getRemoteStorage().setHttpProxySettings(
- globalHttpProxySettings.convertToModel( rsc.getRemoteProxySettings() ) );
- }
- else
- {
- repoConfig.getRemoteStorage().setHttpProxySettings( new CRemoteHttpProxySettings() );
-
- repoConfig.getRemoteStorage().getHttpProxySettings().setBlockInheritance( true );
- }
- }
- else
- {
- repoConfig.getRemoteStorage().setHttpProxySettings( null );
- }
}
}
}
28 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/DefaultProxySelector.java
View
@@ -1,28 +0,0 @@
-/*
- * Sonatype Nexus (TM) Open Source Version
- * Copyright (c) 2007-2013 Sonatype, Inc.
- * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
- *
- * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
- * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
- * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
- * Eclipse Foundation. All other trademarks are the property of their respective owners.
- */
-package org.sonatype.nexus.proxy.repository;
-
-/**
- * A default proxy selector implementation that implements the "default" proxy selection that was supported with nexus
- * up to version 1.3.
- *
- * @author cstamas
- */
-public class DefaultProxySelector
- implements ProxySelector
-{
- public RemoteProxySettings select( ProxyRepository proxy, String url )
- {
- return proxy.getRemoteProxySettings();
- }
-}
67 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/DefaultRemoteHttpProxySettings.java
View
@@ -0,0 +1,67 @@
+/*
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2013 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.proxy.repository;
+
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Default {@link RemoteHttpProxySettings} implementation.
+ *
+ * @since 2.5
+ */
+public class DefaultRemoteHttpProxySettings
+ implements RemoteHttpProxySettings
+{
+
+ private String hostname;
+
+ private int port;
+
+ private RemoteAuthenticationSettings proxyAuthentication;
+
+ public boolean isEnabled()
+ {
+ return StringUtils.isNotBlank( getHostname() ) && getPort() != 0;
+ }
+
+ public String getHostname()
+ {
+ return hostname;
+ }
+
+ public void setHostname( String hostname )
+ {
+ this.hostname = hostname;
+ }
+
+ public int getPort()
+ {
+ return port;
+ }
+
+ public void setPort( int port )
+ {
+ this.port = port;
+ }
+
+ public RemoteAuthenticationSettings getProxyAuthentication()
+ {
+ return proxyAuthentication;
+ }
+
+ public void setProxyAuthentication( RemoteAuthenticationSettings proxyAuthentication )
+ {
+ this.proxyAuthentication = proxyAuthentication;
+ }
+
+}
64 nexus-core/src/main/java/org/sonatype/nexus/proxy/repository/DefaultRemoteProxySettings.java
View
@@ -15,64 +15,39 @@
import java.util.HashSet;
import java.util.Set;
-import org.codehaus.plexus.util.StringUtils;
+import com.google.common.collect.Sets;
+/**
+ * Default {@link RemoteProxySettings} implementation.
+ */
public class DefaultRemoteProxySettings
implements RemoteProxySettings
{
- private boolean blockInheritance;
- private String hostname;
+ private RemoteHttpProxySettings httpProxySettings;
- private int port;
-
- private Set<String> nonProxyHosts = new HashSet<String>();
+ private RemoteHttpProxySettings httpsProxySettings;
- private RemoteAuthenticationSettings proxyAuthentication;
+ private Set<String> nonProxyHosts = Sets.newHashSet();
- public boolean isEnabled()
+ public RemoteHttpProxySettings getHttpProxySettings()
{
- return StringUtils.isNotBlank( getHostname() ) && getPort() != 0;
+ return httpProxySettings;
}
- public boolean isBlockInheritance()
+ public void setHttpProxySettings( final RemoteHttpProxySettings httpProxySettings )
{
- return blockInheritance;
+ this.httpProxySettings = httpProxySettings;
}
- public void setBlockInheritance( boolean blockInheritance )
+ public RemoteHttpProxySettings getHttpsProxySettings()
{
- this.blockInheritance = blockInheritance;
+ return httpsProxySettings;
}
- public String getHostname()
+ public void setHttpsProxySettings( final RemoteHttpProxySettings httpsProxySettings )
{
- return hostname;
- }
-
- public void setHostname( String hostname )