Search in sources :

Example 1 with HttpProxyServerBootstrap

use of org.littleshoot.proxy.HttpProxyServerBootstrap 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();
}
Also used : ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HttpProxyServerBootstrap(org.littleshoot.proxy.HttpProxyServerBootstrap)

Example 2 with HttpProxyServerBootstrap

use of org.littleshoot.proxy.HttpProxyServerBootstrap in project bnd by bndtools.

the class HttpClientProxyTest method createPromiscuousHttpProxy.

void createPromiscuousHttpProxy() {
    HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer.bootstrap().withPort(++httpProxyPort);
    httpProxy = bootstrap.start();
}
Also used : HttpProxyServerBootstrap(org.littleshoot.proxy.HttpProxyServerBootstrap)

Example 3 with HttpProxyServerBootstrap

use of org.littleshoot.proxy.HttpProxyServerBootstrap 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();
}
Also used : ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HttpProxyServerBootstrap(org.littleshoot.proxy.HttpProxyServerBootstrap)

Example 4 with HttpProxyServerBootstrap

use of org.littleshoot.proxy.HttpProxyServerBootstrap in project java-cloudant by cloudant.

the class HttpProxyTest method setupAndStartProxy.

/**
 * Starts a littleproxy instance that will proxy the requests. Applies appropriate configuration
 * options to the proxy based on the test parameters.
 *
 * @throws Exception
 */
@BeforeEach
public void setupAndStartProxy(final boolean okUsable, final boolean useSecureProxy, final boolean useHttpsServer, final boolean useProxyAuth) throws Exception {
    HttpProxyServerBootstrap proxyBoostrap = DefaultHttpProxyServer.bootstrap().withAllowLocalOnly(// only run on localhost
    true).withAuthenticateSslClients(// we aren't checking client certs
    false);
    if (useProxyAuth) {
        // check the proxy user and password
        ProxyAuthenticator pa = new ProxyAuthenticator() {

            @Override
            public boolean authenticate(String userName, String password) {
                return (mockProxyUser.equals(userName) && mockProxyPass.equals(password));
            }

            @Override
            public String getRealm() {
                return null;
            }
        };
        proxyBoostrap.withProxyAuthenticator(pa);
    }
    if (useSecureProxy) {
        proxyBoostrap.withSslEngineSource(new SslEngineSource() {

            @Override
            public SSLEngine newSslEngine() {
                return MockWebServerResources.getSSLContext().createSSLEngine();
            }

            @Override
            public SSLEngine newSslEngine(String peerHost, int peerPort) {
                return MockWebServerResources.getSSLContext().createSSLEngine(peerHost, peerPort);
            }
        });
    }
    // Start the proxy server
    proxy = proxyBoostrap.start();
}
Also used : ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) SslEngineSource(org.littleshoot.proxy.SslEngineSource) SSLEngine(javax.net.ssl.SSLEngine) HttpProxyServerBootstrap(org.littleshoot.proxy.HttpProxyServerBootstrap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HttpProxyServerBootstrap (org.littleshoot.proxy.HttpProxyServerBootstrap)4 ProxyAuthenticator (org.littleshoot.proxy.ProxyAuthenticator)3 SSLEngine (javax.net.ssl.SSLEngine)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SslEngineSource (org.littleshoot.proxy.SslEngineSource)1