Removed AUTH and SM classes

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1689156 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2015-07-04 13:43:20 +00:00
parent 2f66271de9
commit fe175a845a
23 changed files with 92 additions and 203 deletions

View File

@ -30,10 +30,10 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeType;
@ -205,9 +205,9 @@ public class WindowsNegotiateScheme extends NonStandardAuthScheme {
final CharArrayBuffer buffer = new CharArrayBuffer(scheme.length() + 30);
if (isProxy()) {
buffer.append(AUTH.PROXY_AUTH_RESP);
buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
} else {
buffer.append(AUTH.WWW_AUTH_RESP);
buffer.append(HttpHeaders.AUTHORIZATION);
}
buffer.append(": ");
buffer.append(scheme); // NTLM or Negotiate

View File

@ -29,11 +29,11 @@ package org.apache.http.impl.auth.win;
import java.io.IOException;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.CredentialsProvider;
@ -75,7 +75,7 @@ public class TestWindowsNegotiateScheme extends LocalServerTestBase {
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
response.addHeader(AUTH.WWW_AUTH, AuthSchemes.SPNEGO);
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.SPNEGO);
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
}

View File

@ -1,64 +0,0 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.auth;
import org.apache.http.annotation.Immutable;
/**
* Constants and static helpers related to the HTTP authentication.
*
*
* @since 4.0
*/
@Immutable
public final class AUTH {
/**
* The www authenticate challange header.
*/
public static final String WWW_AUTH = "WWW-Authenticate";
/**
* The www authenticate response header.
*/
public static final String WWW_AUTH_RESP = "Authorization";
/**
* The proxy authenticate challange header.
*/
public static final String PROXY_AUTH = "Proxy-Authenticate";
/**
* The proxy authenticate response header.
*/
public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
private AUTH() {
}
}

View File

@ -43,7 +43,6 @@ import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SM;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
@ -88,7 +87,7 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
this.log.debug("Cookie origin not specified in HTTP context");
return;
}
final HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
final HeaderIterator it = response.headerIterator("Set-Cookie");
processCookies(it, cookieSpec, cookieOrigin, cookieStore);
}

View File

@ -1,41 +0,0 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.cookie;
/**
* Constants and static helpers related to the HTTP state management.
*
*
* @since 4.0
*/
public interface SM {
public static final String COOKIE = "Cookie";
public static final String SET_COOKIE = "Set-Cookie";
}

View File

@ -35,9 +35,9 @@ import java.nio.charset.Charset;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeType;
@ -107,9 +107,9 @@ public class BasicScheme extends StandardAuthScheme {
Args.notNull(request, "HTTP request");
final CharArrayBuffer buffer = new CharArrayBuffer(32);
if (isProxy()) {
buffer.append(AUTH.PROXY_AUTH_RESP);
buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
} else {
buffer.append(AUTH.WWW_AUTH_RESP);
buffer.append(HttpHeaders.AUTHORIZATION);
}
buffer.append(": Basic ");

View File

@ -40,9 +40,9 @@ import java.util.StringTokenizer;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeType;
@ -324,9 +324,9 @@ public class DigestScheme extends StandardAuthScheme {
final CharArrayBuffer buffer = new CharArrayBuffer(128);
if (isProxy()) {
buffer.append(AUTH.PROXY_AUTH_RESP);
buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
} else {
buffer.append(AUTH.WWW_AUTH_RESP);
buffer.append(HttpHeaders.AUTHORIZATION);
}
buffer.append(": Digest ");

View File

@ -33,10 +33,10 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeType;
@ -235,9 +235,9 @@ public abstract class GGSSchemeBase extends NonStandardAuthScheme {
}
final CharArrayBuffer buffer = new CharArrayBuffer(32);
if (isProxy()) {
buffer.append(AUTH.PROXY_AUTH_RESP);
buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
} else {
buffer.append(AUTH.WWW_AUTH_RESP);
buffer.append(HttpHeaders.AUTHORIZATION);
}
buffer.append(": Negotiate ");
buffer.append(tokenstr);

View File

@ -27,9 +27,9 @@
package org.apache.http.impl.auth;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeType;
@ -144,9 +144,9 @@ public class NTLMScheme extends NonStandardAuthScheme {
}
final CharArrayBuffer buffer = new CharArrayBuffer(32);
if (isProxy()) {
buffer.append(AUTH.PROXY_AUTH_RESP);
buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
} else {
buffer.append(AUTH.WWW_AUTH_RESP);
buffer.append(HttpHeaders.AUTHORIZATION);
}
buffer.append(": NTLM ");
buffer.append(response);

View File

@ -33,11 +33,11 @@ import java.net.Socket;
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthState;
@ -198,7 +198,7 @@ public class ProxyClient {
conn.close();
}
// discard previous auth header
connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
} else {
break;
}

View File

@ -47,7 +47,6 @@ import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookiePriorityComparator;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SM;
import org.apache.http.message.BufferedHeader;
import org.apache.http.message.ParserCursor;
import org.apache.http.message.TokenParser;
@ -110,7 +109,7 @@ public class RFC6265CookieSpec implements CookieSpec {
public final List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException {
Args.notNull(header, "Header");
Args.notNull(origin, "Cookie origin");
if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE)) {
if (!header.getName().equalsIgnoreCase("Set-Cookie")) {
throw new MalformedCookieException("Unrecognized cookie header: '" + header.toString() + "'");
}
final CharArrayBuffer buffer;
@ -217,7 +216,7 @@ public class RFC6265CookieSpec implements CookieSpec {
sortedCookies = cookies;
}
final CharArrayBuffer buffer = new CharArrayBuffer(20 * sortedCookies.size());
buffer.append(SM.COOKIE);
buffer.append("Cookie");
buffer.append(": ");
for (int n = 0; n < sortedCookies.size(); n++) {
final Cookie cookie = sortedCookies.get(n);

View File

@ -39,11 +39,11 @@ import org.apache.http.HttpClientConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthProtocolState;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.ChallengeType;
@ -244,13 +244,13 @@ public class MainClientExec implements ClientExecChain {
this.log.debug("Executing request " + request.getRequestLine());
}
if (!request.containsHeader(AUTH.WWW_AUTH_RESP)) {
if (!request.containsHeader(HttpHeaders.AUTHORIZATION)) {
if (this.log.isDebugEnabled()) {
this.log.debug("Target auth state: " + targetAuthState.getState());
}
this.authenticator.generateAuthResponse(request, targetAuthState, context);
}
if (!request.containsHeader(AUTH.PROXY_AUTH_RESP) && !route.isTunnelled()) {
if (!request.containsHeader(HttpHeaders.PROXY_AUTHORIZATION) && !route.isTunnelled()) {
if (this.log.isDebugEnabled()) {
this.log.debug("Proxy auth state: " + proxyAuthState.getState());
}
@ -306,11 +306,11 @@ public class MainClientExec implements ClientExecChain {
}
// discard previous auth headers
final HttpRequest original = request.getOriginal();
if (!original.containsHeader(AUTH.WWW_AUTH_RESP)) {
request.removeHeaders(AUTH.WWW_AUTH_RESP);
if (!original.containsHeader(HttpHeaders.AUTHORIZATION)) {
request.removeHeaders(HttpHeaders.AUTHORIZATION);
}
if (!original.containsHeader(AUTH.PROXY_AUTH_RESP)) {
request.removeHeaders(AUTH.PROXY_AUTH_RESP);
if (!original.containsHeader(HttpHeaders.PROXY_AUTHORIZATION)) {
request.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
}
} else {
break;
@ -454,7 +454,7 @@ public class MainClientExec implements ClientExecChain {
context);
}
connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
this.authenticator.generateAuthResponse(connect, proxyAuthState, context);
response = this.requestExecutor.execute(connect, managedConn, context);

View File

@ -43,7 +43,6 @@ import org.apache.http.conn.routing.RouteInfo.TunnelType;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.cookie.SM;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.impl.cookie.IgnoreSpecProvider;
@ -116,7 +115,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(1, headers.length);
Assert.assertEquals("name1=value1; name2=value2", headers[0].getValue());
@ -144,7 +143,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(0, headers.length);
}
@ -164,7 +163,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(0, headers.length);
}
@ -184,7 +183,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(0, headers.length);
}
@ -204,7 +203,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(0, headers.length);
}
@ -222,7 +221,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(0, headers.length);
}
@ -247,7 +246,7 @@ public class TestRequestAddCookies {
final CookieSpec cookieSpec = context.getCookieSpec();
Assert.assertTrue(cookieSpec instanceof RFC6265StrictSpec);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
final Header[] headers1 = request.getHeaders("Cookie");
Assert.assertNotNull(headers1);
Assert.assertEquals(1, headers1.length);
Assert.assertEquals("name1=value1; name2=value2", headers1[0].getValue());
@ -372,7 +371,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(1, headers.length);
Assert.assertEquals("name1=value1; name2=value2", headers[0].getValue());
@ -401,7 +400,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers = request.getHeaders(SM.COOKIE);
final Header[] headers = request.getHeaders("Cookie");
Assert.assertNotNull(headers);
Assert.assertEquals(0, headers.length);
}
@ -437,7 +436,7 @@ public class TestRequestAddCookies {
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
final Header[] headers1 = request.getHeaders("Cookie");
Assert.assertNotNull(headers1);
Assert.assertEquals(1, headers1.length);

View File

@ -35,7 +35,6 @@ import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.SM;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.RFC6265LaxSpec;
import org.apache.http.message.BasicHttpResponse;
@ -73,7 +72,7 @@ public class TestResponseProcessCookies {
@Test
public void testParseCookies() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
response.addHeader("Set-Cookie", "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
@ -96,7 +95,7 @@ public class TestResponseProcessCookies {
@Test
public void testNoCookieOrigin() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
response.addHeader("Set-Cookie", "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, null);
@ -114,7 +113,7 @@ public class TestResponseProcessCookies {
@Test
public void testNoCookieSpec() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
response.addHeader("Set-Cookie", "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
@ -132,7 +131,7 @@ public class TestResponseProcessCookies {
@Test
public void testNoCookieStore() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
response.addHeader("Set-Cookie", "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);

View File

@ -35,8 +35,8 @@ import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpRequest;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.ChallengeType;
@ -105,7 +105,7 @@ public class TestBasicScheme {
final String expected = "Basic " + EncodingUtils.getAsciiString(
Base64.encodeBase64(EncodingUtils.getAsciiBytes("testuser:testpass")));
Assert.assertEquals(AUTH.WWW_AUTH_RESP, authResponse.getName());
Assert.assertEquals(HttpHeaders.AUTHORIZATION, authResponse.getName());
Assert.assertEquals(expected, authResponse.getValue());
Assert.assertEquals("test", authscheme.getRealm());
Assert.assertTrue(authscheme.isComplete());
@ -127,7 +127,7 @@ public class TestBasicScheme {
final String expected = "Basic " + EncodingUtils.getAsciiString(
Base64.encodeBase64(EncodingUtils.getAsciiBytes("testuser:testpass")));
Assert.assertEquals(AUTH.PROXY_AUTH_RESP, authResponse.getName());
Assert.assertEquals(HttpHeaders.PROXY_AUTHORIZATION, authResponse.getName());
Assert.assertEquals(expected, authResponse.getValue());
Assert.assertEquals("test", authscheme.getRealm());
Assert.assertTrue(authscheme.isComplete());

View File

@ -35,7 +35,6 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthOption;
import org.apache.http.auth.AuthProtocolState;
import org.apache.http.auth.AuthScheme;
@ -160,9 +159,9 @@ public class TestHttpAuthenticator {
public void testAuthentication() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -196,8 +195,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationNoSupportedChallenges() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "This realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "That realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "This realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "That realm=\"realm1\", nonce=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -209,8 +208,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationNoCredentials() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
this.credentialsProvider.clear();
@ -224,8 +223,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationFailed() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
this.authState.setState(AuthProtocolState.CHALLENGED);
this.authState.update(this.authScheme, this.credentials);
@ -244,8 +243,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationFailedPreviously() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
this.authState.setState(AuthProtocolState.FAILURE);
@ -261,9 +260,9 @@ public class TestHttpAuthenticator {
public void testAuthenticationFailure() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -280,9 +279,9 @@ public class TestHttpAuthenticator {
public void testAuthenticationHandshaking() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", stale=true, nonce=\"1234\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", stale=true, nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -299,8 +298,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationNoMatchingChallenge() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -323,7 +322,7 @@ public class TestHttpAuthenticator {
public void testAuthenticationException() throws Exception {
final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "blah blah blah"));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "blah blah blah"));
this.authState.setState(AuthProtocolState.CHALLENGED);
@ -345,7 +344,7 @@ public class TestHttpAuthenticator {
this.httpAuthenticator.generateAuthResponse(request, authState, context);
Assert.assertFalse(request.containsHeader(AUTH.WWW_AUTH_RESP));
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
Mockito.verify(this.authScheme, Mockito.never()).authenticate(
Mockito.any(Credentials.class),
@ -362,11 +361,11 @@ public class TestHttpAuthenticator {
Mockito.when(this.authScheme.authenticate(
Mockito.any(Credentials.class),
Mockito.any(HttpRequest.class),
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
this.httpAuthenticator.generateAuthResponse(request, authState, context);
Assert.assertTrue(request.containsHeader(AUTH.WWW_AUTH_RESP));
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
Mockito.verify(this.authScheme).authenticate(this.credentials, request, this.context);
}
@ -382,7 +381,7 @@ public class TestHttpAuthenticator {
Mockito.when(this.authScheme.authenticate(
Mockito.any(Credentials.class),
Mockito.any(HttpRequest.class),
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
this.httpAuthenticator.generateAuthResponse(request, authState, context);
@ -390,7 +389,7 @@ public class TestHttpAuthenticator {
Assert.assertSame(this.credentials, this.authState.getCredentials());
Assert.assertNull(this.authState.getAuthOptions());
Assert.assertTrue(request.containsHeader(AUTH.WWW_AUTH_RESP));
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
Mockito.verify(this.authScheme).authenticate(this.credentials, request, this.context);
}
@ -410,7 +409,7 @@ public class TestHttpAuthenticator {
Mockito.when(authScheme2.authenticate(
Mockito.any(Credentials.class),
Mockito.any(HttpRequest.class),
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
authOptions.add(new AuthOption(authScheme1, this.credentials));
authOptions.add(new AuthOption(authScheme2, this.credentials));
this.authState.update(authOptions);
@ -421,7 +420,7 @@ public class TestHttpAuthenticator {
Assert.assertSame(this.credentials, this.authState.getCredentials());
Assert.assertNull(this.authState.getAuthOptions());
Assert.assertTrue(request.containsHeader(AUTH.WWW_AUTH_RESP));
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
Mockito.verify(authScheme1, Mockito.times(1)).authenticate(this.credentials, request, this.context);
Mockito.verify(authScheme2, Mockito.times(1)).authenticate(this.credentials, request, this.context);
@ -437,7 +436,7 @@ public class TestHttpAuthenticator {
Mockito.when(this.authScheme.authenticate(
Mockito.any(Credentials.class),
Mockito.any(HttpRequest.class),
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
this.httpAuthenticator.generateAuthResponse(request, authState, context);
@ -445,7 +444,7 @@ public class TestHttpAuthenticator {
Assert.assertSame(this.credentials, this.authState.getCredentials());
Assert.assertNull(this.authState.getAuthOptions());
Assert.assertTrue(request.containsHeader(AUTH.WWW_AUTH_RESP));
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
Mockito.verify(this.authScheme).authenticate(this.credentials, request, this.context);
}
@ -460,11 +459,11 @@ public class TestHttpAuthenticator {
Mockito.when(this.authScheme.authenticate(
Mockito.any(Credentials.class),
Mockito.any(HttpRequest.class),
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
this.httpAuthenticator.generateAuthResponse(request, authState, context);
Assert.assertFalse(request.containsHeader(AUTH.WWW_AUTH_RESP));
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
Mockito.verify(this.authScheme, Mockito.never()).authenticate(
Mockito.any(Credentials.class),

View File

@ -245,5 +245,5 @@ public class TestAuthenticationStrategy {
final AuthOption option1 = options.remove();
Assert.assertTrue(option1.getAuthScheme() instanceof BasicScheme);
}
}

View File

@ -35,12 +35,12 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpInetConnection;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthChallenge;
import org.apache.http.auth.AuthOption;
import org.apache.http.auth.AuthScope;
@ -424,7 +424,7 @@ public class TestClientAuthentication extends LocalServerTestBase {
final String givenCreds = (String) context.getAttribute("creds");
if (givenCreds == null || !givenCreds.equals(this.realmCreds)) {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
response.addHeader(AUTH.WWW_AUTH, "Basic realm=\"" + this.realm + "\"");
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"" + this.realm + "\"");
} else {
response.setStatusCode(HttpStatus.SC_OK);
final StringEntity entity = new StringEntity("success", Consts.ASCII);

View File

@ -31,12 +31,12 @@ import java.io.IOException;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.CredentialsProvider;
@ -68,8 +68,8 @@ public class TestClientAuthenticationFallBack extends LocalServerTestBase {
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
response.addHeader(AUTH.WWW_AUTH, "Digest realm=\"test realm\" invalid");
response.addHeader(AUTH.WWW_AUTH, "Basic realm=\"test realm\"");
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"test realm\" invalid");
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test realm\"");
}
}

View File

@ -33,12 +33,12 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthScope;
@ -78,7 +78,7 @@ public class TestClientReauthentication extends LocalServerTestBase {
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
response.addHeader(AUTH.WWW_AUTH, "MyBasic realm=\"test realm\"");
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "MyBasic realm=\"test realm\"");
}
}

View File

@ -48,7 +48,6 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.cookie.SM;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;
@ -679,7 +678,7 @@ public class TestRedirects extends LocalServerTestBase {
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
final Header[] headers = reqWrapper.getHeaders(SM.COOKIE);
final Header[] headers = reqWrapper.getHeaders("Cookie");
Assert.assertEquals("There can only be one (cookie)", 1, headers.length);
}

View File

@ -32,9 +32,9 @@ import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpRequest;
import org.apache.http.ProtocolException;
import org.apache.http.auth.AUTH;
import org.apache.http.util.EncodingUtils;
public class BasicAuthTokenExtractor {
@ -42,7 +42,7 @@ public class BasicAuthTokenExtractor {
public String extract(final HttpRequest request) throws HttpException {
String auth = null;
final Header h = request.getFirstHeader(AUTH.WWW_AUTH_RESP);
final Header h = request.getFirstHeader(HttpHeaders.AUTHORIZATION);
if (h != null) {
final String s = h.getValue();
if (s != null) {

View File

@ -30,10 +30,10 @@ package org.apache.http.localserver;
import java.io.IOException;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AUTH;
import org.apache.http.protocol.HttpContext;
public class ResponseBasicUnauthorized implements HttpResponseInterceptor {
@ -43,8 +43,8 @@ public class ResponseBasicUnauthorized implements HttpResponseInterceptor {
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
if (!response.containsHeader(AUTH.WWW_AUTH)) {
response.addHeader(AUTH.WWW_AUTH, "Basic realm=\"test realm\"");
if (!response.containsHeader(HttpHeaders.WWW_AUTHENTICATE)) {
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test realm\"");
}
}
}