1
1
/**
2
2
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
3
3
*
4
- * Licensed under the Eclipse Public License version 1.0, available at
5
- * http://www.eclipse.org/legal/epl-v10.html
4
+ * Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
6
5
*/
7
6
package org .jboss .forge .addon .configuration .proxy ;
8
7
8
+ import java .util .Arrays ;
9
+ import java .util .List ;
9
10
import org .jboss .forge .addon .configuration .Configuration ;
10
11
11
12
public class ProxySettings
@@ -15,29 +16,38 @@ public class ProxySettings
15
16
private static final String PROXY_CONFIG_PORT_KEY = "port" ;
16
17
private static final String PROXY_CONFIG_USERNAME_KEY = "username" ;
17
18
private static final String PROXY_CONFIG_PASSWORD_KEY = "password" ;
19
+ private static final String PROXY_CONFIG_NON_PROXY_HOSTS = "nonProxyHosts" ;
18
20
19
21
private final String proxyHost ;
20
22
private final int proxyPort ;
21
23
private final String proxyUserName ;
22
24
private final String proxyPassword ;
25
+ private final List <String > nonProxyHosts ;
23
26
24
- private ProxySettings (String proxyHost , int proxyPort , String proxyUserName , String proxyPassword )
27
+ private ProxySettings (String proxyHost , int proxyPort , String proxyUserName , String proxyPassword ,
28
+ List <String > nonProxyHosts )
25
29
{
26
30
this .proxyHost = proxyHost ;
27
31
this .proxyPort = proxyPort ;
28
32
this .proxyUserName = proxyUserName ;
29
33
this .proxyPassword = proxyPassword ;
34
+ this .nonProxyHosts = nonProxyHosts ;
30
35
}
31
36
32
37
public static ProxySettings fromHostAndPort (String proxyHost , int proxyPort )
33
38
{
34
- return new ProxySettings (proxyHost , proxyPort , null , null );
39
+ return new ProxySettings (proxyHost , proxyPort , null , null , null );
40
+ }
41
+
42
+ public static ProxySettings fromHostPortAndNonProxyHosts (String proxyHost , int proxyPort , List <String > nonProxyHosts )
43
+ {
44
+ return new ProxySettings (proxyHost , proxyPort , null , null , nonProxyHosts );
35
45
}
36
46
37
47
public static ProxySettings fromHostPortAndCredentials (String proxyHost , int proxyPort ,
38
48
String proxyUserName , String proxyPassword )
39
49
{
40
- return new ProxySettings (proxyHost , proxyPort , proxyUserName , proxyPassword );
50
+ return new ProxySettings (proxyHost , proxyPort , proxyUserName , proxyPassword , null );
41
51
}
42
52
43
53
public static ProxySettings fromForgeConfiguration (Configuration configuration )
@@ -46,9 +56,20 @@ public static ProxySettings fromForgeConfiguration(Configuration configuration)
46
56
Configuration proxyConfig = configuration .subset ("proxy" );
47
57
if (proxyConfig != null && !proxyConfig .isEmpty ())
48
58
{
49
- return new ProxySettings (proxyConfig .getString (PROXY_CONFIG_HOST_KEY ),
50
- proxyConfig .getInt (PROXY_CONFIG_PORT_KEY ), proxyConfig .getString (PROXY_CONFIG_USERNAME_KEY ),
51
- proxyConfig .getString (PROXY_CONFIG_PASSWORD_KEY ));
59
+ final String nonProxyHosts = proxyConfig .getString (PROXY_CONFIG_NON_PROXY_HOSTS );
60
+ List <String > nonProxyHostsList = null ;
61
+ if (nonProxyHosts != null )
62
+ {
63
+ nonProxyHostsList = Arrays .asList (nonProxyHosts .split ("," ));
64
+ }
65
+
66
+ return new ProxySettings (
67
+ proxyConfig .getString (PROXY_CONFIG_HOST_KEY ),
68
+ proxyConfig .getInt (PROXY_CONFIG_PORT_KEY ),
69
+ proxyConfig .getString (PROXY_CONFIG_USERNAME_KEY ),
70
+ proxyConfig .getString (PROXY_CONFIG_PASSWORD_KEY ),
71
+ nonProxyHostsList
72
+ );
52
73
}
53
74
else
54
75
{
@@ -76,6 +97,11 @@ public String getProxyPassword()
76
97
return proxyPassword ;
77
98
}
78
99
100
+ public List <String > getNonProxyHosts ()
101
+ {
102
+ return nonProxyHosts ;
103
+ }
104
+
79
105
public boolean isAuthenticationSupported ()
80
106
{
81
107
return proxyUserName != null && !"" .equals (proxyUserName );
0 commit comments