mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-10 03:56:17 +00:00
Properly name instance and method variables of AuthExchange
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1695265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
86aa813080
commit
b1f2b6825a
@ -86,7 +86,7 @@ public boolean isChallenged(
|
|||||||
final HttpHost host,
|
final HttpHost host,
|
||||||
final ChallengeType challengeType,
|
final ChallengeType challengeType,
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
final AuthExchange authState,
|
final AuthExchange authExchange,
|
||||||
final HttpContext context) {
|
final HttpContext context) {
|
||||||
final int challengeCode;
|
final int challengeCode;
|
||||||
switch (challengeType) {
|
switch (challengeType) {
|
||||||
@ -104,22 +104,22 @@ public boolean isChallenged(
|
|||||||
|
|
||||||
if (response.getStatusLine().getStatusCode() == challengeCode) {
|
if (response.getStatusLine().getStatusCode() == challengeCode) {
|
||||||
this.log.debug("Authentication required");
|
this.log.debug("Authentication required");
|
||||||
if (authState.getState() == AuthExchange.State.SUCCESS) {
|
if (authExchange.getState() == AuthExchange.State.SUCCESS) {
|
||||||
clearCache(host, clientContext);
|
clearCache(host, clientContext);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
switch (authState.getState()) {
|
switch (authExchange.getState()) {
|
||||||
case CHALLENGED:
|
case CHALLENGED:
|
||||||
case HANDSHAKE:
|
case HANDSHAKE:
|
||||||
this.log.debug("Authentication succeeded");
|
this.log.debug("Authentication succeeded");
|
||||||
authState.setState(AuthExchange.State.SUCCESS);
|
authExchange.setState(AuthExchange.State.SUCCESS);
|
||||||
updateCache(host, authState.getAuthScheme(), clientContext);
|
updateCache(host, authExchange.getAuthScheme(), clientContext);
|
||||||
break;
|
break;
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
authState.setState(AuthExchange.State.UNCHALLENGED);
|
authExchange.setState(AuthExchange.State.UNCHALLENGED);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ public boolean prepareAuthResponse(
|
|||||||
final ChallengeType challengeType,
|
final ChallengeType challengeType,
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
final AuthenticationStrategy authStrategy,
|
final AuthenticationStrategy authStrategy,
|
||||||
final AuthExchange authState,
|
final AuthExchange authExchange,
|
||||||
final HttpContext context) {
|
final HttpContext context) {
|
||||||
|
|
||||||
if (this.log.isDebugEnabled()) {
|
if (this.log.isDebugEnabled()) {
|
||||||
@ -177,21 +177,21 @@ public boolean prepareAuthResponse(
|
|||||||
if (challengeMap.isEmpty()) {
|
if (challengeMap.isEmpty()) {
|
||||||
this.log.debug("Response contains no valid authentication challenges");
|
this.log.debug("Response contains no valid authentication challenges");
|
||||||
clearCache(host, clientContext);
|
clearCache(host, clientContext);
|
||||||
authState.reset();
|
authExchange.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (authState.getState()) {
|
switch (authExchange.getState()) {
|
||||||
case FAILURE:
|
case FAILURE:
|
||||||
return false;
|
return false;
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
authState.reset();
|
authExchange.reset();
|
||||||
break;
|
break;
|
||||||
case CHALLENGED:
|
case CHALLENGED:
|
||||||
case HANDSHAKE:
|
case HANDSHAKE:
|
||||||
Asserts.notNull(authState.getAuthScheme(), "AuthScheme");
|
Asserts.notNull(authExchange.getAuthScheme(), "AuthScheme");
|
||||||
case UNCHALLENGED:
|
case UNCHALLENGED:
|
||||||
final AuthScheme authScheme = authState.getAuthScheme();
|
final AuthScheme authScheme = authExchange.getAuthScheme();
|
||||||
if (authScheme != null) {
|
if (authScheme != null) {
|
||||||
final String id = authScheme.getName();
|
final String id = authScheme.getName();
|
||||||
final AuthChallenge challenge = challengeMap.get(id.toLowerCase(Locale.ROOT));
|
final AuthChallenge challenge = challengeMap.get(id.toLowerCase(Locale.ROOT));
|
||||||
@ -204,21 +204,21 @@ public boolean prepareAuthResponse(
|
|||||||
this.log.warn(ex.getMessage());
|
this.log.warn(ex.getMessage());
|
||||||
}
|
}
|
||||||
clearCache(host, clientContext);
|
clearCache(host, clientContext);
|
||||||
authState.reset();
|
authExchange.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (authScheme.isChallengeComplete()) {
|
if (authScheme.isChallengeComplete()) {
|
||||||
this.log.debug("Authentication failed");
|
this.log.debug("Authentication failed");
|
||||||
clearCache(host, clientContext);
|
clearCache(host, clientContext);
|
||||||
authState.reset();
|
authExchange.reset();
|
||||||
authState.setState(AuthExchange.State.FAILURE);
|
authExchange.setState(AuthExchange.State.FAILURE);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
authState.setState(AuthExchange.State.HANDSHAKE);
|
authExchange.setState(AuthExchange.State.HANDSHAKE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
authState.reset();
|
authExchange.reset();
|
||||||
// Retry authentication with a different scheme
|
// Retry authentication with a different scheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,9 +250,9 @@ public boolean prepareAuthResponse(
|
|||||||
if (this.log.isDebugEnabled()) {
|
if (this.log.isDebugEnabled()) {
|
||||||
this.log.debug("Selected authentication options: " + authOptions);
|
this.log.debug("Selected authentication options: " + authOptions);
|
||||||
}
|
}
|
||||||
authState.reset();
|
authExchange.reset();
|
||||||
authState.setState(AuthExchange.State.CHALLENGED);
|
authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
authState.setOptions(authOptions);
|
authExchange.setOptions(authOptions);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -263,10 +263,10 @@ public void addAuthResponse(
|
|||||||
final HttpHost host,
|
final HttpHost host,
|
||||||
final ChallengeType challengeType,
|
final ChallengeType challengeType,
|
||||||
final HttpRequest request,
|
final HttpRequest request,
|
||||||
final AuthExchange authState,
|
final AuthExchange authExchange,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) throws HttpException, IOException {
|
||||||
AuthScheme authScheme = authState.getAuthScheme();
|
AuthScheme authScheme = authExchange.getAuthScheme();
|
||||||
switch (authState.getState()) {
|
switch (authExchange.getState()) {
|
||||||
case FAILURE:
|
case FAILURE:
|
||||||
return;
|
return;
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
@ -279,11 +279,11 @@ public void addAuthResponse(
|
|||||||
Asserts.notNull(authScheme, "AuthScheme");
|
Asserts.notNull(authScheme, "AuthScheme");
|
||||||
break;
|
break;
|
||||||
case CHALLENGED:
|
case CHALLENGED:
|
||||||
final Queue<AuthScheme> authOptions = authState.getAuthOptions();
|
final Queue<AuthScheme> authOptions = authExchange.getAuthOptions();
|
||||||
if (authOptions != null) {
|
if (authOptions != null) {
|
||||||
while (!authOptions.isEmpty()) {
|
while (!authOptions.isEmpty()) {
|
||||||
authScheme = authOptions.remove();
|
authScheme = authOptions.remove();
|
||||||
authState.select(authScheme);
|
authExchange.select(authScheme);
|
||||||
if (this.log.isDebugEnabled()) {
|
if (this.log.isDebugEnabled()) {
|
||||||
this.log.debug("Generating response to an authentication challenge using "
|
this.log.debug("Generating response to an authentication challenge using "
|
||||||
+ authScheme.getName() + " scheme");
|
+ authScheme.getName() + " scheme");
|
||||||
|
@ -88,8 +88,8 @@ public Object getUserToken(final HttpRoute route, final HttpContext context) {
|
|||||||
return userPrincipal;
|
return userPrincipal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Principal getAuthPrincipal(final AuthExchange authState) {
|
private static Principal getAuthPrincipal(final AuthExchange authExchange) {
|
||||||
final AuthScheme scheme = authState.getAuthScheme();
|
final AuthScheme scheme = authExchange.getAuthScheme();
|
||||||
if (scheme != null && scheme.isConnectionBased()) {
|
if (scheme != null && scheme.isConnectionBased()) {
|
||||||
return scheme.getPrincipal();
|
return scheme.getPrincipal();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
@SuppressWarnings({"boxing","static-access"})
|
@SuppressWarnings({"boxing","static-access"})
|
||||||
public class TestHttpAuthenticator {
|
public class TestHttpAuthenticator {
|
||||||
|
|
||||||
private AuthExchange authState;
|
private AuthExchange authExchange;
|
||||||
private AuthScheme authScheme;
|
private AuthScheme authScheme;
|
||||||
private HttpContext context;
|
private HttpContext context;
|
||||||
private HttpHost defaultHost;
|
private HttpHost defaultHost;
|
||||||
@ -74,7 +74,7 @@ public class TestHttpAuthenticator {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.authState = new AuthExchange();
|
this.authExchange = new AuthExchange();
|
||||||
this.authScheme = Mockito.mock(AuthScheme.class);
|
this.authScheme = Mockito.mock(AuthScheme.class);
|
||||||
Mockito.when(this.authScheme.getName()).thenReturn("Basic");
|
Mockito.when(this.authScheme.getName()).thenReturn("Basic");
|
||||||
Mockito.when(this.authScheme.isChallengeComplete()).thenReturn(Boolean.TRUE);
|
Mockito.when(this.authScheme.isChallengeComplete()).thenReturn(Boolean.TRUE);
|
||||||
@ -94,11 +94,11 @@ public void setUp() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAuthState() throws Exception {
|
public void testUpdateAuthExchange() throws Exception {
|
||||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||||
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||||
Assert.assertTrue(this.httpAuthenticator.isChallenged(
|
Assert.assertTrue(this.httpAuthenticator.isChallenged(
|
||||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||||
Mockito.verifyZeroInteractions(this.authCache);
|
Mockito.verifyZeroInteractions(this.authCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,11 +107,11 @@ public void testAuthenticationRequestedAfterSuccess() throws Exception {
|
|||||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||||
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||||
|
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
this.authState.setState(AuthExchange.State.SUCCESS);
|
this.authExchange.setState(AuthExchange.State.SUCCESS);
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.isChallenged(
|
Assert.assertTrue(this.httpAuthenticator.isChallenged(
|
||||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||||
|
|
||||||
Mockito.verify(this.authCache).remove(this.defaultHost);
|
Mockito.verify(this.authCache).remove(this.defaultHost);
|
||||||
}
|
}
|
||||||
@ -121,19 +121,19 @@ public void testAuthenticationNotRequestedUnchallenged() throws Exception {
|
|||||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
||||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authExchange.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationNotRequestedSuccess1() throws Exception {
|
public void testAuthenticationNotRequestedSuccess1() throws Exception {
|
||||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
||||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authExchange.getState());
|
||||||
|
|
||||||
Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
|
Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
|
||||||
}
|
}
|
||||||
@ -141,12 +141,12 @@ public void testAuthenticationNotRequestedSuccess1() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testAuthenticationNotRequestedSuccess2() throws Exception {
|
public void testAuthenticationNotRequestedSuccess2() throws Exception {
|
||||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
this.authState.setState(AuthExchange.State.HANDSHAKE);
|
this.authExchange.setState(AuthExchange.State.HANDSHAKE);
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
||||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authExchange.getState());
|
||||||
|
|
||||||
Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
|
Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
|
||||||
}
|
}
|
||||||
@ -165,10 +165,10 @@ public void testAuthentication() throws Exception {
|
|||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authExchange.getState());
|
||||||
|
|
||||||
final Queue<AuthScheme> options = this.authState.getAuthOptions();
|
final Queue<AuthScheme> options = this.authExchange.getAuthOptions();
|
||||||
Assert.assertNotNull(options);
|
Assert.assertNotNull(options);
|
||||||
final AuthScheme authScheme1 = options.poll();
|
final AuthScheme authScheme1 = options.poll();
|
||||||
Assert.assertNotNull(authScheme1);
|
Assert.assertNotNull(authScheme1);
|
||||||
@ -192,10 +192,10 @@ public void testAuthenticationCredentialsForBasic() throws Exception {
|
|||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authExchange.getState());
|
||||||
|
|
||||||
final Queue<AuthScheme> options = this.authState.getAuthOptions();
|
final Queue<AuthScheme> options = this.authExchange.getAuthOptions();
|
||||||
Assert.assertNotNull(options);
|
Assert.assertNotNull(options);
|
||||||
final AuthScheme authScheme1 = options.poll();
|
final AuthScheme authScheme1 = options.poll();
|
||||||
Assert.assertNotNull(authScheme1);
|
Assert.assertNotNull(authScheme1);
|
||||||
@ -211,7 +211,7 @@ public void testAuthenticationNoChallenges() throws Exception {
|
|||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -224,7 +224,7 @@ public void testAuthenticationNoSupportedChallenges() throws Exception {
|
|||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -237,7 +237,7 @@ public void testAuthenticationNoCredentials() throws Exception {
|
|||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -247,15 +247,15 @@ public void testAuthenticationFailed() throws Exception {
|
|||||||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
|
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, "Digest realm=\"realm1\", nonce=\"1234\""));
|
||||||
|
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
|
|
||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
|
|
||||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.FAILURE, this.authExchange.getState());
|
||||||
|
|
||||||
Mockito.verify(this.authCache).remove(host);
|
Mockito.verify(this.authCache).remove(host);
|
||||||
}
|
}
|
||||||
@ -267,14 +267,14 @@ public void testAuthenticationFailedPreviously() throws Exception {
|
|||||||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
|
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, "Digest realm=\"realm1\", nonce=\"1234\""));
|
||||||
|
|
||||||
this.authState.setState(AuthExchange.State.FAILURE);
|
this.authExchange.setState(AuthExchange.State.FAILURE);
|
||||||
|
|
||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
|
|
||||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.FAILURE, this.authExchange.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -287,12 +287,12 @@ public void testAuthenticationFailure() throws Exception {
|
|||||||
|
|
||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
this.authState.select(new BasicScheme());
|
this.authExchange.select(new BasicScheme());
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.FAILURE, this.authExchange.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -305,13 +305,13 @@ public void testAuthenticationHandshaking() throws Exception {
|
|||||||
|
|
||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
this.authState.select(new DigestScheme());
|
this.authExchange.select(new DigestScheme());
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
|
|
||||||
Assert.assertEquals(AuthExchange.State.HANDSHAKE, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.HANDSHAKE, this.authExchange.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -326,14 +326,14 @@ public void testAuthenticationNoMatchingChallenge() throws Exception {
|
|||||||
|
|
||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
this.authState.select(new BasicScheme());
|
this.authExchange.select(new BasicScheme());
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authExchange.getState());
|
||||||
|
|
||||||
final Queue<AuthScheme> options = this.authState.getAuthOptions();
|
final Queue<AuthScheme> options = this.authExchange.getAuthOptions();
|
||||||
Assert.assertNotNull(options);
|
Assert.assertNotNull(options);
|
||||||
final AuthScheme authScheme1 = options.poll();
|
final AuthScheme authScheme1 = options.poll();
|
||||||
Assert.assertNotNull(authScheme1);
|
Assert.assertNotNull(authScheme1);
|
||||||
@ -347,24 +347,24 @@ public void testAuthenticationException() throws Exception {
|
|||||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "blah blah blah"));
|
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "blah blah blah"));
|
||||||
|
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
|
|
||||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||||
|
|
||||||
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authState.getState());
|
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authExchange.getState());
|
||||||
Assert.assertNull(this.authState.getAuthScheme());
|
Assert.assertNull(this.authExchange.getAuthScheme());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthFailureState() throws Exception {
|
public void testAuthFailureState() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthExchange.State.FAILURE);
|
this.authExchange.setState(AuthExchange.State.FAILURE);
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
|
|
||||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||||
|
|
||||||
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||||
|
|
||||||
@ -377,15 +377,15 @@ public void testAuthFailureState() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testAuthChallengeStateNoOption() throws Exception {
|
public void testAuthChallengeStateNoOption() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
|
|
||||||
Mockito.when(this.authScheme.generateAuthResponse(
|
Mockito.when(this.authScheme.generateAuthResponse(
|
||||||
Mockito.eq(defaultHost),
|
Mockito.eq(defaultHost),
|
||||||
Mockito.any(HttpRequest.class),
|
Mockito.any(HttpRequest.class),
|
||||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||||
|
|
||||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||||
|
|
||||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||||
}
|
}
|
||||||
@ -393,20 +393,20 @@ public void testAuthChallengeStateNoOption() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testAuthChallengeStateOneOptions() throws Exception {
|
public void testAuthChallengeStateOneOptions() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
final LinkedList<AuthScheme> authOptions = new LinkedList<>();
|
final LinkedList<AuthScheme> authOptions = new LinkedList<>();
|
||||||
authOptions.add(this.authScheme);
|
authOptions.add(this.authScheme);
|
||||||
this.authState.setOptions(authOptions);
|
this.authExchange.setOptions(authOptions);
|
||||||
|
|
||||||
Mockito.when(this.authScheme.generateAuthResponse(
|
Mockito.when(this.authScheme.generateAuthResponse(
|
||||||
Mockito.eq(defaultHost),
|
Mockito.eq(defaultHost),
|
||||||
Mockito.any(HttpRequest.class),
|
Mockito.any(HttpRequest.class),
|
||||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||||
|
|
||||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||||
|
|
||||||
Assert.assertSame(this.authScheme, this.authState.getAuthScheme());
|
Assert.assertSame(this.authScheme, this.authExchange.getAuthScheme());
|
||||||
Assert.assertNull(this.authState.getAuthOptions());
|
Assert.assertNull(this.authExchange.getAuthOptions());
|
||||||
|
|
||||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||||
}
|
}
|
||||||
@ -414,7 +414,7 @@ public void testAuthChallengeStateOneOptions() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testAuthChallengeStateMultipleOption() throws Exception {
|
public void testAuthChallengeStateMultipleOption() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||||
|
|
||||||
final LinkedList<AuthScheme> authOptions = new LinkedList<>();
|
final LinkedList<AuthScheme> authOptions = new LinkedList<>();
|
||||||
final AuthScheme authScheme1 = Mockito.mock(AuthScheme.class);
|
final AuthScheme authScheme1 = Mockito.mock(AuthScheme.class);
|
||||||
@ -429,12 +429,12 @@ public void testAuthChallengeStateMultipleOption() throws Exception {
|
|||||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||||
authOptions.add(authScheme1);
|
authOptions.add(authScheme1);
|
||||||
authOptions.add(authScheme2);
|
authOptions.add(authScheme2);
|
||||||
this.authState.setOptions(authOptions);
|
this.authExchange.setOptions(authOptions);
|
||||||
|
|
||||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||||
|
|
||||||
Assert.assertSame(authScheme2, this.authState.getAuthScheme());
|
Assert.assertSame(authScheme2, this.authExchange.getAuthScheme());
|
||||||
Assert.assertNull(this.authState.getAuthOptions());
|
Assert.assertNull(this.authExchange.getAuthOptions());
|
||||||
|
|
||||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||||
}
|
}
|
||||||
@ -442,8 +442,8 @@ public void testAuthChallengeStateMultipleOption() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testAuthSuccess() throws Exception {
|
public void testAuthSuccess() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthExchange.State.SUCCESS);
|
this.authExchange.setState(AuthExchange.State.SUCCESS);
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
|
|
||||||
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.FALSE);
|
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.FALSE);
|
||||||
Mockito.when(this.authScheme.generateAuthResponse(
|
Mockito.when(this.authScheme.generateAuthResponse(
|
||||||
@ -451,10 +451,10 @@ public void testAuthSuccess() throws Exception {
|
|||||||
Mockito.any(HttpRequest.class),
|
Mockito.any(HttpRequest.class),
|
||||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||||
|
|
||||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||||
|
|
||||||
Assert.assertSame(this.authScheme, this.authState.getAuthScheme());
|
Assert.assertSame(this.authScheme, this.authExchange.getAuthScheme());
|
||||||
Assert.assertNull(this.authState.getAuthOptions());
|
Assert.assertNull(this.authExchange.getAuthOptions());
|
||||||
|
|
||||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||||
}
|
}
|
||||||
@ -462,8 +462,8 @@ public void testAuthSuccess() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testAuthSuccessConnectionBased() throws Exception {
|
public void testAuthSuccessConnectionBased() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthExchange.State.SUCCESS);
|
this.authExchange.setState(AuthExchange.State.SUCCESS);
|
||||||
this.authState.select(this.authScheme);
|
this.authExchange.select(this.authScheme);
|
||||||
|
|
||||||
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.TRUE);
|
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.TRUE);
|
||||||
Mockito.when(this.authScheme.generateAuthResponse(
|
Mockito.when(this.authScheme.generateAuthResponse(
|
||||||
@ -471,7 +471,7 @@ public void testAuthSuccessConnectionBased() throws Exception {
|
|||||||
Mockito.any(HttpRequest.class),
|
Mockito.any(HttpRequest.class),
|
||||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||||
|
|
||||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||||
|
|
||||||
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user