Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync.net; |
michael@0 | 6 | |
michael@0 | 7 | import ch.boye.httpclientandroidlib.Header; |
michael@0 | 8 | import ch.boye.httpclientandroidlib.auth.Credentials; |
michael@0 | 9 | import ch.boye.httpclientandroidlib.auth.UsernamePasswordCredentials; |
michael@0 | 10 | import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; |
michael@0 | 11 | import ch.boye.httpclientandroidlib.impl.auth.BasicScheme; |
michael@0 | 12 | import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; |
michael@0 | 13 | import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * An <code>AuthHeaderProvider</code> that returns an HTTP Basic auth header. |
michael@0 | 17 | */ |
michael@0 | 18 | public class BasicAuthHeaderProvider implements AuthHeaderProvider { |
michael@0 | 19 | protected final String credentials; |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * Constructor. |
michael@0 | 23 | * |
michael@0 | 24 | * @param credentials string in form "user:pass". |
michael@0 | 25 | */ |
michael@0 | 26 | public BasicAuthHeaderProvider(String credentials) { |
michael@0 | 27 | this.credentials = credentials; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Constructor. |
michael@0 | 32 | * |
michael@0 | 33 | * @param user username. |
michael@0 | 34 | * @param pass password. |
michael@0 | 35 | */ |
michael@0 | 36 | public BasicAuthHeaderProvider(String user, String pass) { |
michael@0 | 37 | this(user + ":" + pass); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Return a Header object representing an Authentication header for HTTP |
michael@0 | 42 | * Basic. |
michael@0 | 43 | */ |
michael@0 | 44 | @Override |
michael@0 | 45 | public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) { |
michael@0 | 46 | Credentials creds = new UsernamePasswordCredentials(credentials); |
michael@0 | 47 | |
michael@0 | 48 | // This must be UTF-8 to generate the same Basic Auth headers as desktop for non-ASCII passwords. |
michael@0 | 49 | return BasicScheme.authenticate(creds, "UTF-8", false); |
michael@0 | 50 | } |
michael@0 | 51 | } |