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

org.browsermob.proxy.http.WildcardMatchingCredentialsProvider Maven / Gradle / Ivy

There is a newer version: 2.0-beta-7
Show newest version
package org.browsermob.proxy.http;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;

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

public class WildcardMatchingCredentialsProvider implements CredentialsProvider {
    private final HashMap credMap = new HashMap();

    @Override
    public synchronized void setCredentials(AuthScope authscope, Credentials credentials) {
        credMap.put(authscope, credentials);
    }

    @Override
    public synchronized Credentials getCredentials(AuthScope authscope) {
        for (Map.Entry entry : credMap.entrySet()) {
            if (entry.getKey().getHost() == null) {
                continue;
            }
            if (authscope.getHost().contains(entry.getKey().getHost())) {
                return entry.getValue();
            }
        }

        return null;
    }

    @Override
    public synchronized void clear() {
        credMap.clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy