Search in sources :

Example 1 with ProxyAuthenticator

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();
}
Also used : ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) ThreadPoolConfiguration(org.littleshoot.proxy.impl.ThreadPoolConfiguration) ServerSocket(java.net.ServerSocket)

Example 2 with ProxyAuthenticator

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

Example 3 with ProxyAuthenticator

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

Example 4 with ProxyAuthenticator

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();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 5 with ProxyAuthenticator

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

Aggregations

ProxyAuthenticator (org.littleshoot.proxy.ProxyAuthenticator)7 HttpProxyServerBootstrap (org.littleshoot.proxy.HttpProxyServerBootstrap)3 HashMap (java.util.HashMap)2 SimpleCredentials (javax.jcr.SimpleCredentials)2 RepositoryService (org.apache.jackrabbit.spi.RepositoryService)2 HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)2 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)2 ServerSocket (java.net.ServerSocket)1 RepositoryException (javax.jcr.RepositoryException)1 SSLEngine (javax.net.ssl.SSLEngine)1 BeforeClass (org.junit.BeforeClass)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SslEngineSource (org.littleshoot.proxy.SslEngineSource)1 ThreadPoolConfiguration (org.littleshoot.proxy.impl.ThreadPoolConfiguration)1