use of org.littleshoot.proxy.ProxyAuthenticator in project nifi by apache.
the class TestHttpClient method startProxyServerWithAuth.
private static void startProxyServerWithAuth() throws IOException {
int proxyServerPort;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
proxyServerPort = serverSocket.getLocalPort();
}
proxyServerWithAuth = DefaultHttpProxyServer.bootstrap().withPort(proxyServerPort).withAllowLocalOnly(true).withProxyAuthenticator(new ProxyAuthenticator() {
@Override
public boolean authenticate(String userName, String password) {
return PROXY_USER.equals(userName) && PROXY_PASSWORD.equals(password);
}
@Override
public String getRealm() {
return "NiFi Unit Test";
}
}).withThreadPoolConfiguration(new ThreadPoolConfiguration().withAcceptorThreads(2).withClientToProxyWorkerThreads(4).withProxyToServerWorkerThreads(4)).start();
}
use of org.littleshoot.proxy.ProxyAuthenticator in project bnd by bndtools.
the class HttpClientProxyTest method createAuthenticationHttpProxy.
// we use different ports because the servers seem to linger
void createAuthenticationHttpProxy() {
HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer.bootstrap().withPort(++httpProxyPort);
bootstrap.withProxyAuthenticator(new ProxyAuthenticator() {
@Override
public boolean authenticate(String user, String password) {
System.out.println("Authenticating " + user + " : " + password);
authenticationCalled.set(true);
return "proxyuser".equals(user) && "good".equals(password);
}
});
httpProxy = bootstrap.start();
}
use of org.littleshoot.proxy.ProxyAuthenticator in project components by Talend.
the class SalesforceProxyTestIT method setupProxy.
@BeforeClass
public static void setupProxy() {
ProxyAuthenticator auth = new ProxyAuthenticator() {
@Override
public boolean authenticate(String username, String password) {
return proxyUsername.equals(username) && proxyPassword.equals(password);
}
@Override
public String getRealm() {
return null;
}
};
server = DefaultHttpProxyServer.bootstrap().withPort(proxyPort).withProxyAuthenticator(auth).start();
setProxySettingForClient();
}
use of org.littleshoot.proxy.ProxyAuthenticator in project jackrabbit by apache.
the class ConnectionTest method testObtainViaProxyWithInvalidCredentials.
public void testObtainViaProxyWithInvalidCredentials() throws URISyntaxException, RepositoryException {
ProxyAuthenticator authenticator = new ProxyAuthenticator() {
@Override
public String getRealm() {
return null;
}
@Override
public boolean authenticate(String userName, String password) {
return false;
}
};
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
0).withProxyAuthenticator(authenticator).start();
try {
Map<String, String> parameters = new HashMap<>();
ConnectionOptions.Builder builder = ConnectionOptions.builder();
builder.proxyHost("127.0.0.1");
builder.proxyPort(proxyServer.getListenAddress().getPort());
builder.proxyUsername("test");
builder.proxyPassword("invalid");
parameters.putAll(builder.build().toServiceFactoryParameters());
RepositoryService repositoryService = createRepositoryService(false, parameters);
try {
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
fail("should have failed with proxy authentication failure!");
} catch (RepositoryException expected) {
}
} finally {
proxyServer.stop();
}
}
use of org.littleshoot.proxy.ProxyAuthenticator in project bnd by bndtools.
the class Standalone method createHttpProxy.
void createHttpProxy() {
HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer.bootstrap().withPort(9091);
bootstrap.withProxyAuthenticator(new ProxyAuthenticator() {
@Override
public boolean authenticate(String user, String password) {
System.out.println("Authenticating " + user + " : " + password);
return "proxyuser".equals(user) && "good".equals(password);
}
});
bootstrap.start();
}
Aggregations