mirror of https://github.com/apache/archiva.git
Modifying NetworkProxy class. Adding tests.
This commit is contained in:
parent
c7fb08d2cb
commit
ebf95723a5
|
@ -49,11 +49,6 @@
|
|||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-repository-layer</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -27,6 +27,12 @@ import org.apache.archiva.repository.RepositoryType;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A proxy registry is central access point for accessing a proxy. It gives access to the proxy handlers
|
||||
* that are registered for the different repository types.
|
||||
*
|
||||
* @author Martin Stockhammer <martin_s@apache.org>
|
||||
*/
|
||||
public interface ProxyRegistry {
|
||||
|
||||
/**
|
|
@ -20,6 +20,8 @@ package org.apache.archiva.proxy.model;
|
|||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class NetworkProxy
|
||||
implements Serializable
|
||||
|
@ -50,7 +52,7 @@ public class NetworkProxy
|
|||
/**
|
||||
* The proxy password.
|
||||
*/
|
||||
private String password;
|
||||
private char[] password;
|
||||
|
||||
/**
|
||||
* @since 1.4-M3
|
||||
|
@ -64,14 +66,14 @@ public class NetworkProxy
|
|||
// no op
|
||||
}
|
||||
|
||||
public NetworkProxy( String id, String protocol, String host, int port, String username, String password )
|
||||
public NetworkProxy(String id, String protocol, String host, int port, String username, char[] password )
|
||||
{
|
||||
this.id = id;
|
||||
this.protocol = protocol;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
setPassword(password);
|
||||
}
|
||||
|
||||
public String getId()
|
||||
|
@ -124,14 +126,17 @@ public class NetworkProxy
|
|||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
public char[] getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword( String password )
|
||||
public void setPassword(char[] password )
|
||||
{
|
||||
this.password = password;
|
||||
if (this.password!=null) {
|
||||
Arrays.fill(this.password, '0');
|
||||
}
|
||||
this.password = Arrays.copyOf(password, password.length);
|
||||
}
|
||||
|
||||
public boolean isUseNtlm()
|
||||
|
@ -158,12 +163,7 @@ public class NetworkProxy
|
|||
|
||||
NetworkProxy that = (NetworkProxy) o;
|
||||
|
||||
if ( id != null ? !id.equals( that.id ) : that.id != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
package org.apache.archiva.proxy.model;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class NetworkProxyTest {
|
||||
|
||||
@Test
|
||||
public void getId() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertNull(proxy.getId());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals("test-proxy", proxy.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setId() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
proxy.setId("test-proxy1");
|
||||
assertEquals("test-proxy1",proxy.getId());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
proxy.setId("test-proxy2");
|
||||
assertEquals("test-proxy2", proxy.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProtocol() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertEquals("http", proxy.getProtocol());
|
||||
proxy = new NetworkProxy("test-proxy", "https", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals("https", proxy.getProtocol());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setProtocol() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
proxy.setProtocol("https");
|
||||
assertEquals("https", proxy.getProtocol());
|
||||
proxy = new NetworkProxy("test-proxy", "https", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
proxy.setProtocol("http");
|
||||
assertEquals("http", proxy.getProtocol());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHost() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertNull(proxy.getHost());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals("test.apache.org", proxy.getHost());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHost() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
proxy.setHost("test1.apache.org");
|
||||
assertEquals("test1.apache.org",proxy.getHost());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
proxy.setHost("test2.apache.org");
|
||||
assertEquals("test2.apache.org", proxy.getHost());
|
||||
proxy.setHost("test3.apache.org");
|
||||
assertEquals("test3.apache.org", proxy.getHost());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPort() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertEquals(8080,proxy.getPort());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals(80, proxy.getPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPort() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
proxy.setPort(8090);
|
||||
assertEquals(8090,proxy.getPort());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
proxy.setPort(9090);
|
||||
assertEquals(9090, proxy.getPort());
|
||||
proxy.setPort(9091);
|
||||
assertEquals(9091, proxy.getPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUsername() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertNull(proxy.getUsername());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals("testuser", proxy.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUsername() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
proxy.setUsername("testuser1");
|
||||
assertEquals("testuser1",proxy.getUsername());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
proxy.setUsername("testuser2");
|
||||
assertEquals("testuser2", proxy.getUsername());
|
||||
proxy.setUsername("testuser3");
|
||||
assertEquals("testuser3", proxy.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPassword() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertNull(proxy.getPassword());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals("xxxx", new String(proxy.getPassword()));
|
||||
char[] testPwd = {'a', 'b', 'c', 'd'};
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", testPwd);
|
||||
assertEquals("abcd", new String(proxy.getPassword()));
|
||||
testPwd[0]='0';
|
||||
assertEquals("abcd", new String(proxy.getPassword()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPassword() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertNull(proxy.getPassword());
|
||||
proxy.setPassword("ucdx".toCharArray());
|
||||
assertEquals("ucdx", new String(proxy.getPassword()));
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertEquals("xxxx", new String(proxy.getPassword()));
|
||||
char[] testPwd = {'a', 'b', 'c', 'd'};
|
||||
proxy.setPassword(testPwd);
|
||||
assertEquals("abcd", new String(proxy.getPassword()));
|
||||
testPwd[0]='0';
|
||||
assertEquals("abcd", new String(proxy.getPassword()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUseNtlm() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertFalse(proxy.isUseNtlm());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertFalse(proxy.isUseNtlm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUseNtlm() {
|
||||
NetworkProxy proxy = new NetworkProxy();
|
||||
assertFalse(proxy.isUseNtlm());
|
||||
proxy.setUseNtlm(true);
|
||||
assertTrue(proxy.isUseNtlm());
|
||||
proxy = new NetworkProxy("test-proxy", "http", "test.apache.org", 80, "testuser", "xxxx".toCharArray());
|
||||
assertFalse(proxy.isUseNtlm());
|
||||
proxy.setUseNtlm(true);
|
||||
assertTrue(proxy.isUseNtlm());
|
||||
}
|
||||
|
||||
}
|
|
@ -59,10 +59,6 @@
|
|||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-filelock</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-repository-scanner</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-scheduler-repository-api</artifactId>
|
||||
|
|
|
@ -36,10 +36,15 @@ import javax.inject.Inject;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Default proxy registry implementation. Uses the archiva configuration for accessing and storing the
|
||||
* proxy information.
|
||||
*
|
||||
*/
|
||||
@Service("proxyRegistry#default")
|
||||
public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListener {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ArchivaProxyRegistry.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(ArchivaProxyRegistry.class);
|
||||
|
||||
@Inject
|
||||
ArchivaConfiguration archivaConfiguration;
|
||||
|
@ -83,7 +88,7 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
|
|||
proxy.setHost(networkProxyConfig.getHost());
|
||||
proxy.setPort(networkProxyConfig.getPort());
|
||||
proxy.setUsername(networkProxyConfig.getUsername());
|
||||
proxy.setPassword(networkProxyConfig.getPassword());
|
||||
proxy.setPassword(networkProxyConfig.getPassword().toCharArray());
|
||||
proxy.setUseNtlm(networkProxyConfig.isUseNtlm());
|
||||
|
||||
this.networkProxyMap.put(key, proxy);
|
||||
|
|
|
@ -237,7 +237,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
|
|||
np.setId(p.getId());
|
||||
np.setUseNtlm(p.isUseNtlm());
|
||||
np.setUsername(p.getUsername());
|
||||
np.setPassword(p.getPassword());
|
||||
np.setPassword(p.getPassword() == null ? new char[0] : p.getPassword().toCharArray());
|
||||
np.setProtocol(p.getProtocol());
|
||||
np.setHost(p.getHost());
|
||||
np.setPort(p.getPort());
|
||||
|
|
|
@ -316,7 +316,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
|
|||
proxyInfo.setHost( networkProxy.getHost( ) );
|
||||
proxyInfo.setPort( networkProxy.getPort( ) );
|
||||
proxyInfo.setUserName( networkProxy.getUsername( ) );
|
||||
proxyInfo.setPassword( networkProxy.getPassword( ) );
|
||||
proxyInfo.setPassword(new String(networkProxy.getPassword()));
|
||||
}
|
||||
AuthenticationInfo authenticationInfo = null;
|
||||
if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials) )
|
||||
|
|
|
@ -330,7 +330,7 @@ public class MavenIndexManager implements ArchivaIndexManager {
|
|||
proxyInfo.setHost( networkProxy.getHost( ) );
|
||||
proxyInfo.setPort( networkProxy.getPort( ) );
|
||||
proxyInfo.setUserName( networkProxy.getUsername( ) );
|
||||
proxyInfo.setPassword( networkProxy.getPassword( ) );
|
||||
proxyInfo.setPassword( new String(networkProxy.getPassword( )) );
|
||||
}
|
||||
AuthenticationInfo authenticationInfo = null;
|
||||
if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials ) )
|
||||
|
|
|
@ -87,7 +87,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
|
|||
proxy.setHost(networkProxyDef.getHost());
|
||||
proxy.setPort(networkProxyDef.getPort());
|
||||
proxy.setUserName(networkProxyDef.getUsername());
|
||||
proxy.setPassword(networkProxyDef.getPassword());
|
||||
proxy.setPassword(new String(networkProxyDef.getPassword()));
|
||||
|
||||
this.networkProxyMap.put(key, proxy);
|
||||
}
|
||||
|
|
|
@ -190,7 +190,9 @@ public class HttpProxyTransferTest
|
|||
public void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
server.stop();
|
||||
if (server!=null) {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,12 +19,7 @@ package org.apache.archiva.proxy;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.archiva.configuration.Configuration;
|
||||
import org.apache.archiva.configuration.ConfigurationListener;
|
||||
import org.apache.archiva.configuration.FileType;
|
||||
import org.apache.archiva.configuration.FileTypes;
|
||||
import org.apache.archiva.configuration.RepositoryScanningConfiguration;
|
||||
import org.apache.archiva.configuration.*;
|
||||
import org.apache.archiva.redback.components.registry.Registry;
|
||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||
|
@ -36,11 +31,7 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.PostConstruct;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* MockConfiguration
|
||||
|
@ -84,6 +75,14 @@ public class MockConfiguration
|
|||
return Collections.singletonList( fileType );
|
||||
}
|
||||
} );
|
||||
ArchivaRuntimeConfiguration rt = new ArchivaRuntimeConfiguration();
|
||||
List<String> checksums = new ArrayList<>();
|
||||
checksums.add("MD5");
|
||||
checksums.add("SHA1");
|
||||
checksums.add("SHA256");
|
||||
rt.setChecksumTypes(checksums);
|
||||
configuration.setArchivaRuntimeConfiguration(rt);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -427,7 +427,7 @@ public class RepositoryModelResolver
|
|||
networkProxy.setHost( proxyConnector.getHost() );
|
||||
networkProxy.setPort( proxyConnector.getPort() );
|
||||
networkProxy.setUserName( proxyConnector.getUsername() );
|
||||
networkProxy.setPassword( proxyConnector.getPassword() );
|
||||
networkProxy.setPassword( new String(proxyConnector.getPassword()) );
|
||||
|
||||
String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort()
|
||||
+ " to connect to remote repository " + remoteRepository.getLocation();
|
||||
|
|
|
@ -317,7 +317,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
|
|||
proxyInfo.setHost( networkProxy.getHost( ) );
|
||||
proxyInfo.setPort( networkProxy.getPort( ) );
|
||||
proxyInfo.setUserName( networkProxy.getUsername( ) );
|
||||
proxyInfo.setPassword( networkProxy.getPassword( ) );
|
||||
proxyInfo.setPassword(new String(networkProxy.getPassword()));
|
||||
}
|
||||
AuthenticationInfo authenticationInfo = null;
|
||||
if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials) )
|
||||
|
|
|
@ -165,7 +165,7 @@ public class DownloadRemoteIndexTask
|
|||
proxyInfo.setHost( this.networkProxy.getHost() );
|
||||
proxyInfo.setPort( this.networkProxy.getPort() );
|
||||
proxyInfo.setUserName( this.networkProxy.getUsername() );
|
||||
proxyInfo.setPassword( this.networkProxy.getPassword() );
|
||||
proxyInfo.setPassword( new String(this.networkProxy.getPassword()) );
|
||||
}
|
||||
AuthenticationInfo authenticationInfo = null;
|
||||
if ( this.remoteRepository.getLoginCredentials()!=null && this.remoteRepository.getLoginCredentials() instanceof PasswordCredentials )
|
||||
|
|
|
@ -303,7 +303,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
|
|||
proxyInfo.setHost( networkProxy.getHost( ) );
|
||||
proxyInfo.setPort( networkProxy.getPort( ) );
|
||||
proxyInfo.setUserName( networkProxy.getUsername( ) );
|
||||
proxyInfo.setPassword( networkProxy.getPassword( ) );
|
||||
proxyInfo.setPassword(new String(networkProxy.getPassword()));
|
||||
}
|
||||
AuthenticationInfo authenticationInfo = null;
|
||||
if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials) )
|
||||
|
|
|
@ -167,7 +167,7 @@ public class DefaultRemoteRepositoriesService
|
|||
proxyInfo.setHost(networkProxy.getHost());
|
||||
proxyInfo.setPort(networkProxy.getPort());
|
||||
proxyInfo.setUserName(networkProxy.getUsername());
|
||||
proxyInfo.setPassword(networkProxy.getPassword());
|
||||
proxyInfo.setPassword(new String(networkProxy.getPassword()));
|
||||
}
|
||||
String url = StringUtils.stripEnd(remoteRepository.getUrl(), "/");
|
||||
wagon.connect(new Repository(remoteRepository.getId(), url), proxyInfo);
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -68,18 +68,21 @@
|
|||
<redback.spring-utils.version>2.1</redback.spring-utils.version>
|
||||
<redback.taskqueue.version>2.1</redback.taskqueue.version>
|
||||
|
||||
<!-- dependencies of maven modules -->
|
||||
<jsoup.version>1.12.1</jsoup.version>
|
||||
<rome.version>0.9</rome.version>
|
||||
<cronutils.version>9.0.1</cronutils.version>
|
||||
|
||||
<spring.version>4.3.10.RELEASE</spring.version>
|
||||
|
||||
<javax.jcr.version>2.0</javax.jcr.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
|
||||
<lucene.version>4.10.4</lucene.version>
|
||||
|
||||
<!-- JCR modules -->
|
||||
<javax.jcr.version>2.0</javax.jcr.version>
|
||||
<jcr-oak.version>1.14.0</jcr-oak.version>
|
||||
<!-- Jackrabbit classes are still used for webdav -->
|
||||
<jackrabbit.version>2.15.4</jackrabbit.version>
|
||||
<metrics-core.version>3.1.0</metrics-core.version>
|
||||
|
||||
|
|
Loading…
Reference in New Issue