All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.browserup.bup.mitmproxy.management.AuthBasicManager Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.browserup.bup.mitmproxy.management;

import com.browserup.bup.mitmproxy.MitmProxyProcessManager;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static java.lang.String.valueOf;
import static org.apache.commons.lang3.tuple.Pair.of;

public class AuthBasicManager {
    private final AddonsManagerClient addonsManagerClient;
    private final MitmProxyProcessManager mitmProxyManager;
    private final Map credentials = new HashMap<>();

    public AuthBasicManager(AddonsManagerClient addonsManagerClient, MitmProxyProcessManager mitmProxyManager) {
        this.addonsManagerClient = addonsManagerClient;
        this.mitmProxyManager = mitmProxyManager;
    }

    public void authAuthorization(String domain, String base64EncodedCredentials) {
        credentials.put(domain, base64EncodedCredentials);

        if (!mitmProxyManager.isRunning()) return;

        addonsManagerClient.
                getRequestToAddonsManager(
                        "auth_basic",
                        "auth_authorization",
                        new ArrayList>() {{
                            add(of("domain", valueOf(domain)));
                            add(of("base64EncodedCredentials", valueOf(base64EncodedCredentials)));
                        }},
                        Void.class);
    }

    public void stopAutoAuthorization(String domain) {
        if (!mitmProxyManager.isRunning()) return;

        addonsManagerClient.
                getRequestToAddonsManager(
                        "auth_basic",
                        "stop_authorization",
                        new ArrayList>() {{
                            add(of("domain", valueOf(domain)));
                        }},
                        Void.class);
    }

    public Map getCredentials() {
        return credentials;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy