@@ -0,0 +1,3090 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.jena.atlas.web.auth;%0A%0Aimport java.net.URI;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport org.apache.http.impl.client.AbstractHttpClient;%0Aimport org.apache.http.protocol.HttpContext;%0A%0A/**%0A * A scoped authenticator which is actually a wrapper around other%0A * authenticators and thus can be used to mix and match different authentication%0A * mechanisms to different services as desired%0A * %0A */%0Apublic class DelegatingAuthenticator extends AbstractScopedAuthenticator%3CHttpAuthenticator%3E %7B%0A%0A    private Map%3CURI, HttpAuthenticator%3E authenticators = new HashMap%3CURI, HttpAuthenticator%3E();%0A%0A    /**%0A     * Creates a new delegating authenticator%0A     * %0A     * @param target%0A     *            Target URI%0A     * @param authenticator%0A     *            Authenticator to delegate to%0A     */%0A    public DelegatingAuthenticator(URI target, HttpAuthenticator authenticator) %7B%0A        if (target == null)%0A            throw new IllegalArgumentException(%22Target URI cannot be null%22);%0A        this.authenticators.put(target, authenticator);%0A    %7D%0A%0A    /**%0A     * Creates a new delegating authenticator%0A     * %0A     * @param authenticators%0A     *            Mapping between URIs and authenticators%0A     */%0A    public DelegatingAuthenticator(Map%3CURI, HttpAuthenticator%3E authenticators) %7B%0A        this.authenticators.putAll(authenticators);%0A    %7D%0A%0A    public void apply(AbstractHttpClient client, HttpContext context, URI target) %7B%0A        HttpAuthenticator authenticator = this.findCredentials(target);%0A        if (authenticator != null) %7B%0A            authenticator.apply(client, context, target);%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected HttpAuthenticator getCredentials(URI target) %7B%0A        return this.authenticators.get(target);%0A    %7D%0A%0A    @Override%0A    protected String getUserNameFromCredentials(HttpAuthenticator credentials) %7B%0A        // Not used by this implementation because we override apply() so this%0A        // will never be needed and regardless isn't available%0A        return null;%0A    %7D%0A%0A    @Override%0A    protected char%5B%5D getPasswordFromCredentials(HttpAuthenticator credentials) %7B%0A        // Not used by this implementation because we override apply() so this%0A        // will never be needed and regardless isn't available%0A        return null;%0A    %7D%0A%0A%7D%0A

Add a delegating authenticator which can be used to map different authenticators to different URIs (JENA-480)