Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Base64;
import java.util.concurrent.TimeUnit;

public class FeignProxyConfig {
Expand All @@ -32,10 +33,12 @@ private static OkHttpClient proxiedHttpClient(final ProxyPropertiesProvider prop
final int maxIdleConnections,
final int keepAliveDurationMinutes
) {
String auth = STR."\{propertiesProvider.getProxyUser()}:\{propertiesProvider.getProxyPassword()}";
Authenticator proxyAuthenticator = (_, response) -> {
String credential = Credentials.basic(propertiesProvider.getUser(), propertiesProvider.getPassword());
String credential = Credentials.basic(propertiesProvider.getProxyUser(), propertiesProvider.getProxyPassword());
return response.request().newBuilder()
.header(HttpHeaders.PROXY_AUTHORIZATION, credential)
.header(HttpHeaders.AUTHORIZATION, STR."Basic \{Base64.getEncoder().encodeToString(auth.getBytes())}")
.build();
};

Expand All @@ -47,6 +50,6 @@ private static OkHttpClient proxiedHttpClient(final ProxyPropertiesProvider prop
}

private static Proxy createProxy(ProxyPropertiesProvider propertiesProvider) {
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(propertiesProvider.getHost(), propertiesProvider.getPort()));
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(propertiesProvider.getProxyHost(), propertiesProvider.getProxyPort()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
@ConditionalOnProperty(FixieProxyPropertiesProvider.FIXIE_ENV_VAR)
class FixieProxyPropertiesProvider implements ProxyPropertiesProvider {
static final String FIXIE_ENV_VAR = "FIXIE_URL";
static final String USER_ENV_VAR = "PROXIED_USER_NAME";
static final String PASSWORD_ENV_VAR = "PROXIED_USER_PASSWORD";

private final String proxyUser;
private final String proxyPassword;
private final String proxyHost;
private final int proxyPort;
private final String user;
private final String password;
private final String host;
private final int port;

public FixieProxyPropertiesProvider(final Environment environment) {
final String fixieUrl = environment.getProperty(FIXIE_ENV_VAR);
Objects.requireNonNull(fixieUrl);
final String[] fixieValues = fixieUrl.split("[/(:\\/@)/]+");
this.user = fixieValues[1];
this.password = fixieValues[2];
this.host = fixieValues[3];
this.port = Integer.parseInt(fixieValues[4]);
this.proxyUser = fixieValues[1];
this.proxyPassword = fixieValues[2];
this.proxyHost = fixieValues[3];
this.proxyPort = Integer.parseInt(fixieValues[4]);
this.user = environment.getProperty(USER_ENV_VAR);
this.password = environment.getProperty(PASSWORD_ENV_VAR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@


interface ProxyPropertiesProvider {
String getUser();
String getProxyUser();

String getPassword();
String getProxyPassword();

String getProxyHost();

String getHost();
int getProxyPort();

int getPort();
String getUser();

String getPassword();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ public class FixieProxyPropertiesProviderTest {
void testConstructorSuccess() {
when(environment.getProperty(FixieProxyPropertiesProvider.FIXIE_ENV_VAR))
.thenReturn("http://user:password@host:8080");
when(environment.getProperty(FixieProxyPropertiesProvider.USER_ENV_VAR))
.thenReturn("admin");
when(environment.getProperty(FixieProxyPropertiesProvider.PASSWORD_ENV_VAR))
.thenReturn("pw");

FixieProxyPropertiesProvider fixieProxyPropertiesProvider = new FixieProxyPropertiesProvider(environment);

assertEquals("user", fixieProxyPropertiesProvider.getUser());
assertEquals("password", fixieProxyPropertiesProvider.getPassword());
assertEquals("host", fixieProxyPropertiesProvider.getHost());
assertEquals(8080, fixieProxyPropertiesProvider.getPort());
assertEquals("user", fixieProxyPropertiesProvider.getProxyUser());
assertEquals("password", fixieProxyPropertiesProvider.getProxyPassword());
assertEquals("host", fixieProxyPropertiesProvider.getProxyHost());
assertEquals(8080, fixieProxyPropertiesProvider.getProxyPort());
assertEquals("admin", fixieProxyPropertiesProvider.getUser());
assertEquals("pw", fixieProxyPropertiesProvider.getPassword());
}

@Test
Expand Down
Loading