Search in sources :

Example 1 with BasicAuthentication

use of aQute.bnd.url.BasicAuthentication in project bnd by bndtools.

the class NexusTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    tmpName = "generated/tmp/test/" + getName();
    local = IO.getFile(tmpName + "/local");
    reporter.setTrace(true);
    Config config = new Config();
    IO.delete(local);
    local.mkdirs();
    HttpClient httpClient = new HttpClient();
    httpClient.addURLConnectionHandler(new BasicAuthentication("deployment", "deployment123", Workspace.log));
    repo = new MavenRemoteRepository(local, httpClient, "http://localhost:8081/nexus/content/repositories/snapshots/", reporter);
}
Also used : Config(aQute.http.testservers.HttpTestServer.Config) HttpClient(aQute.bnd.http.HttpClient) BasicAuthentication(aQute.bnd.url.BasicAuthentication)

Example 2 with BasicAuthentication

use of aQute.bnd.url.BasicAuthentication in project bnd by bndtools.

the class ConnectionSettings method createUrlConnectionHandler.

public URLConnectionHandler createUrlConnectionHandler(ServerDTO serverDTO) {
    final Glob match = new Glob(serverDTO.match == null ? serverDTO.id : serverDTO.match);
    final BasicAuthentication basic = getBasicAuthentication(serverDTO.username, serverDTO.password);
    final HttpsVerification https = new HttpsVerification(serverDTO.trust, serverDTO.verify, getParent());
    return new URLConnectionHandler() {

        @Override
        public boolean matches(URL url) {
            String scheme = url.getProtocol().toLowerCase();
            StringBuilder address = new StringBuilder();
            address.append(scheme).append("://").append(url.getHost());
            if (url.getPort() > 0 && url.getPort() != url.getDefaultPort())
                address.append(":").append(url.getPort());
            return match.matcher(address).matches();
        }

        @Override
        public void handle(URLConnection connection) throws Exception {
            if (basic != null)
                basic.handle(connection);
            if (isHttps(connection) && https != null) {
                https.handle(connection);
            }
        }

        boolean isHttps(URLConnection connection) {
            return "https".equalsIgnoreCase(connection.getURL().getProtocol());
        }

        public String toString() {
            return "Server [ match=" + match + ", basic=" + basic + ", https=" + https + "]";
        }
    };
}
Also used : URLConnectionHandler(aQute.bnd.service.url.URLConnectionHandler) HttpsVerification(aQute.bnd.url.HttpsVerification) Glob(aQute.libg.glob.Glob) BasicAuthentication(aQute.bnd.url.BasicAuthentication) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 3 with BasicAuthentication

use of aQute.bnd.url.BasicAuthentication in project bnd by bndtools.

the class AgainstNexusTest method config.

void config(Map<String, String> config) throws Exception {
    if (config == null)
        config = new HashMap<>();
    config.put("local", tmpName + "/local");
    config.put("index", tmpName + "/index");
    config.put("releaseUrl", HTTP_LOCALHOST_8081);
    Processor reporter = new Processor();
    HttpClient client = new HttpClient();
    BasicAuthentication ba = new BasicAuthentication("admin", "admin123", reporter);
    client.addURLConnectionHandler(ba);
    Executor executor = Executors.newCachedThreadPool();
    reporter.addBasicPlugin(client);
    reporter.setTrace(true);
    repo = new MavenBndRepository();
    repo.setReporter(reporter);
    repo.setRegistry(reporter);
    repo.setProperties(config);
}
Also used : Processor(aQute.bnd.osgi.Processor) Executor(java.util.concurrent.Executor) HashMap(java.util.HashMap) HttpClient(aQute.bnd.http.HttpClient) BasicAuthentication(aQute.bnd.url.BasicAuthentication)

Aggregations

BasicAuthentication (aQute.bnd.url.BasicAuthentication)3 HttpClient (aQute.bnd.http.HttpClient)2 Processor (aQute.bnd.osgi.Processor)1 URLConnectionHandler (aQute.bnd.service.url.URLConnectionHandler)1 HttpsVerification (aQute.bnd.url.HttpsVerification)1 Config (aQute.http.testservers.HttpTestServer.Config)1 Glob (aQute.libg.glob.Glob)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 HashMap (java.util.HashMap)1 Executor (java.util.concurrent.Executor)1