Updated AuthState API
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1182317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9edd1acd4f
commit
4d1b157272
|
@ -30,7 +30,6 @@ import java.util.Queue;
|
||||||
|
|
||||||
import org.apache.http.annotation.NotThreadSafe;
|
import org.apache.http.annotation.NotThreadSafe;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides detailed information about the state of the authentication process.
|
* This class provides detailed information about the state of the authentication process.
|
||||||
*
|
*
|
||||||
|
@ -51,6 +50,7 @@ public class AuthState {
|
||||||
/** Credentials selected for authentication */
|
/** Credentials selected for authentication */
|
||||||
private Credentials credentials;
|
private Credentials credentials;
|
||||||
|
|
||||||
|
/** Available auth options */
|
||||||
private Queue<AuthOption> authOptions;
|
private Queue<AuthOption> authOptions;
|
||||||
|
|
||||||
public AuthState() {
|
public AuthState() {
|
||||||
|
@ -59,7 +59,9 @@ public class AuthState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets authentication state.
|
* Resets the auth state.
|
||||||
|
*
|
||||||
|
* @since 4.2
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.state = AuthProtocolState.UNCHALLENGED;
|
this.state = AuthProtocolState.UNCHALLENGED;
|
||||||
|
@ -69,6 +71,89 @@ public class AuthState {
|
||||||
this.credentials = null;
|
this.credentials = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public AuthProtocolState getState() {
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public void setState(final AuthProtocolState state) {
|
||||||
|
this.state = state != null ? state : AuthProtocolState.UNCHALLENGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns actual {@link AuthScheme}. May be null.
|
||||||
|
*/
|
||||||
|
public AuthScheme getAuthScheme() {
|
||||||
|
return this.authScheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns actual {@link Credentials}. May be null.
|
||||||
|
*/
|
||||||
|
public Credentials getCredentials() {
|
||||||
|
return this.credentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the auth state with {@link AuthScheme} and {@link Credentials}.
|
||||||
|
*
|
||||||
|
* @param authScheme auth scheme. May not be null.
|
||||||
|
* @param credentials user crednetials. May not be null.
|
||||||
|
*
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public void update(final AuthScheme authScheme, final Credentials credentials) {
|
||||||
|
if (authScheme == null) {
|
||||||
|
throw new IllegalArgumentException("Auth scheme may not be null or empty");
|
||||||
|
}
|
||||||
|
if (credentials == null) {
|
||||||
|
throw new IllegalArgumentException("Credentials may not be null or empty");
|
||||||
|
}
|
||||||
|
this.authScheme = authScheme;
|
||||||
|
this.credentials = credentials;
|
||||||
|
this.authOptions = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns available {@link AuthOption}s. May be null.
|
||||||
|
*
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public Queue<AuthOption> getAuthOptions() {
|
||||||
|
return this.authOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <code>true</code> if {@link AuthOption}s are available, <code>false</code>
|
||||||
|
* otherwise.
|
||||||
|
*
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public boolean hasAuthOptions() {
|
||||||
|
return this.authOptions != null && !this.authOptions.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the auth state with a queue of {@link AuthOption}s.
|
||||||
|
*
|
||||||
|
* @param authOptions a queue of auth options. May not be null or empty.
|
||||||
|
*
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public void update(final Queue<AuthOption> authOptions) {
|
||||||
|
if (authOptions == null || authOptions.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Queue of auth options may not be null or empty");
|
||||||
|
}
|
||||||
|
this.authOptions = authOptions;
|
||||||
|
this.authScheme = null;
|
||||||
|
this.credentials = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates the authentication state by resetting its parameters.
|
* Invalidates the authentication state by resetting its parameters.
|
||||||
*
|
*
|
||||||
|
@ -88,7 +173,10 @@ public class AuthState {
|
||||||
* Assigns the given {@link AuthScheme authentication scheme}.
|
* Assigns the given {@link AuthScheme authentication scheme}.
|
||||||
*
|
*
|
||||||
* @param authScheme the {@link AuthScheme authentication scheme}
|
* @param authScheme the {@link AuthScheme authentication scheme}
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #update(AuthScheme, Credentials)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setAuthScheme(final AuthScheme authScheme) {
|
public void setAuthScheme(final AuthScheme authScheme) {
|
||||||
if (authScheme == null) {
|
if (authScheme == null) {
|
||||||
reset();
|
reset();
|
||||||
|
@ -97,43 +185,14 @@ public class AuthState {
|
||||||
this.authScheme = authScheme;
|
this.authScheme = authScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link AuthScheme authentication scheme}.
|
|
||||||
*
|
|
||||||
* @return {@link AuthScheme authentication scheme}
|
|
||||||
*/
|
|
||||||
public AuthScheme getAuthScheme() {
|
|
||||||
return this.authScheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
public AuthProtocolState getState() {
|
|
||||||
return this.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
public void setState(final AuthProtocolState state) {
|
|
||||||
this.state = state != null ? state : AuthProtocolState.UNCHALLENGED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns user {@link Credentials} selected for authentication if available
|
|
||||||
*
|
|
||||||
* @return user credentials if available, <code>null</code otherwise
|
|
||||||
*/
|
|
||||||
public Credentials getCredentials() {
|
|
||||||
return this.credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets user {@link Credentials} to be used for authentication
|
* Sets user {@link Credentials} to be used for authentication
|
||||||
*
|
*
|
||||||
* @param credentials User credentials
|
* @param credentials User credentials
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #update(AuthScheme, Credentials)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setCredentials(final Credentials credentials) {
|
public void setCredentials(final Credentials credentials) {
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
@ -162,41 +221,6 @@ public class AuthState {
|
||||||
this.authScope = authScope;
|
this.authScope = authScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns available authentication options.
|
|
||||||
*
|
|
||||||
* @return authentication options, if available, <code>null</null> otherwise.
|
|
||||||
*
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
public Queue<AuthOption> getAuthOptions() {
|
|
||||||
return this.authOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns <code>true</code> if authentication options are available, <code>false</code>
|
|
||||||
* otherwise.
|
|
||||||
*
|
|
||||||
* @return <code>true</code> if authentication options are available, <code>false</code>
|
|
||||||
* otherwise.
|
|
||||||
*
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
public boolean hasAuthOptions() {
|
|
||||||
return this.authOptions != null && !this.authOptions.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets authentication options to select from when authenticating.
|
|
||||||
*
|
|
||||||
* @param authOptions authentication options
|
|
||||||
*
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
public void setAuthOptions(final Queue<AuthOption> authOptions) {
|
|
||||||
this.authOptions = authOptions != null && !authOptions.isEmpty() ? authOptions : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
|
|
@ -127,8 +127,7 @@ public class RequestAuthCache implements HttpRequestInterceptor {
|
||||||
Credentials creds = credsProvider.getCredentials(authScope);
|
Credentials creds = credsProvider.getCredentials(authScope);
|
||||||
|
|
||||||
if (creds != null) {
|
if (creds != null) {
|
||||||
authState.setAuthScheme(authScheme);
|
authState.update(authScheme, creds);
|
||||||
authState.setCredentials(creds);
|
|
||||||
} else {
|
} else {
|
||||||
this.log.debug("No credentials for preemptive authentication");
|
this.log.debug("No credentials for preemptive authentication");
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,7 @@ abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
|
||||||
AuthOption authOption = authOptions.remove();
|
AuthOption authOption = authOptions.remove();
|
||||||
authScheme = authOption.getAuthScheme();
|
authScheme = authOption.getAuthScheme();
|
||||||
creds = authOption.getCredentials();
|
creds = authOption.getCredentials();
|
||||||
authState.setAuthScheme(authScheme);
|
authState.update(authScheme, creds);
|
||||||
authState.setCredentials(creds);
|
|
||||||
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.getSchemeName() + " scheme");
|
+ authScheme.getSchemeName() + " scheme");
|
||||||
|
@ -83,7 +82,6 @@ abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
|
||||||
try {
|
try {
|
||||||
Header header = authenticate(authScheme, creds, request, context);
|
Header header = authenticate(authScheme, creds, request, context);
|
||||||
request.addHeader(header);
|
request.addHeader(header);
|
||||||
authState.setAuthOptions(null);
|
|
||||||
break;
|
break;
|
||||||
} catch (AuthenticationException ex) {
|
} catch (AuthenticationException ex) {
|
||||||
if (this.log.isWarnEnabled()) {
|
if (this.log.isWarnEnabled()) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class HttpAuthenticator {
|
||||||
Queue<AuthOption> authOptions = authStrategy.select(challenges, host, response, context);
|
Queue<AuthOption> authOptions = authStrategy.select(challenges, host, response, context);
|
||||||
if (authOptions != null && !authOptions.isEmpty()) {
|
if (authOptions != null && !authOptions.isEmpty()) {
|
||||||
authState.setState(AuthProtocolState.CHALLENGED);
|
authState.setState(AuthProtocolState.CHALLENGED);
|
||||||
authState.setAuthOptions(authOptions);
|
authState.update(authOptions);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -232,11 +232,9 @@ public class TestRequestAuthCache {
|
||||||
context.setAttribute(ClientContext.AUTH_CACHE, authCache);
|
context.setAttribute(ClientContext.AUTH_CACHE, authCache);
|
||||||
|
|
||||||
this.targetState.setState(AuthProtocolState.CHALLENGED);
|
this.targetState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.targetState.setAuthScheme(new BasicScheme());
|
this.targetState.update(new BasicScheme(), new UsernamePasswordCredentials("user3", "secret3"));
|
||||||
this.targetState.setCredentials(new UsernamePasswordCredentials("user3", "secret3"));
|
|
||||||
this.proxyState.setAuthScheme(new BasicScheme());
|
|
||||||
this.proxyState.setCredentials(new UsernamePasswordCredentials("user4", "secret4"));
|
|
||||||
this.proxyState.setState(AuthProtocolState.CHALLENGED);
|
this.proxyState.setState(AuthProtocolState.CHALLENGED);
|
||||||
|
this.proxyState.update(new BasicScheme(), new UsernamePasswordCredentials("user4", "secret4"));
|
||||||
|
|
||||||
HttpRequestInterceptor interceptor = new RequestAuthCache();
|
HttpRequestInterceptor interceptor = new RequestAuthCache();
|
||||||
interceptor.process(request, context);
|
interceptor.process(request, context);
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class TestRequestAuthenticationBase {
|
||||||
public void testAuthFailureState() throws Exception {
|
public void testAuthFailureState() throws Exception {
|
||||||
HttpRequest request = new BasicHttpRequest("GET", "/");
|
HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthProtocolState.FAILURE);
|
this.authState.setState(AuthProtocolState.FAILURE);
|
||||||
this.authState.setAuthScheme(this.authScheme);
|
this.authState.update(this.authScheme, this.credentials);
|
||||||
|
|
||||||
this.interceptor.process(request, this.context);
|
this.interceptor.process(request, this.context);
|
||||||
|
|
||||||
|
@ -98,8 +98,7 @@ public class TestRequestAuthenticationBase {
|
||||||
public void testAuthChallengeStateNoOption() throws Exception {
|
public void testAuthChallengeStateNoOption() throws Exception {
|
||||||
HttpRequest request = new BasicHttpRequest("GET", "/");
|
HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthProtocolState.CHALLENGED);
|
this.authState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.authState.setAuthScheme(this.authScheme);
|
this.authState.update(this.authScheme, this.credentials);
|
||||||
this.authState.setCredentials(this.credentials);
|
|
||||||
|
|
||||||
Mockito.when(this.authScheme.authenticate(
|
Mockito.when(this.authScheme.authenticate(
|
||||||
Mockito.any(Credentials.class),
|
Mockito.any(Credentials.class),
|
||||||
|
@ -119,7 +118,7 @@ public class TestRequestAuthenticationBase {
|
||||||
this.authState.setState(AuthProtocolState.CHALLENGED);
|
this.authState.setState(AuthProtocolState.CHALLENGED);
|
||||||
LinkedList<AuthOption> authOptions = new LinkedList<AuthOption>();
|
LinkedList<AuthOption> authOptions = new LinkedList<AuthOption>();
|
||||||
authOptions.add(new AuthOption(this.authScheme, this.credentials));
|
authOptions.add(new AuthOption(this.authScheme, this.credentials));
|
||||||
this.authState.setAuthOptions(authOptions);
|
this.authState.update(authOptions);
|
||||||
|
|
||||||
Mockito.when(this.authScheme.authenticate(
|
Mockito.when(this.authScheme.authenticate(
|
||||||
Mockito.any(Credentials.class),
|
Mockito.any(Credentials.class),
|
||||||
|
@ -155,7 +154,7 @@ public class TestRequestAuthenticationBase {
|
||||||
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
|
Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(AUTH.WWW_AUTH_RESP, "stuff"));
|
||||||
authOptions.add(new AuthOption(authScheme1, this.credentials));
|
authOptions.add(new AuthOption(authScheme1, this.credentials));
|
||||||
authOptions.add(new AuthOption(authScheme2, this.credentials));
|
authOptions.add(new AuthOption(authScheme2, this.credentials));
|
||||||
this.authState.setAuthOptions(authOptions);
|
this.authState.update(authOptions);
|
||||||
|
|
||||||
this.interceptor.process(request, this.context);
|
this.interceptor.process(request, this.context);
|
||||||
|
|
||||||
|
@ -173,9 +172,7 @@ public class TestRequestAuthenticationBase {
|
||||||
public void testAuthSuccess() throws Exception {
|
public void testAuthSuccess() throws Exception {
|
||||||
HttpRequest request = new BasicHttpRequest("GET", "/");
|
HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthProtocolState.SUCCESS);
|
this.authState.setState(AuthProtocolState.SUCCESS);
|
||||||
|
this.authState.update(this.authScheme, this.credentials);
|
||||||
this.authState.setAuthScheme(this.authScheme);
|
|
||||||
this.authState.setCredentials(this.credentials);
|
|
||||||
|
|
||||||
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.FALSE);
|
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.FALSE);
|
||||||
Mockito.when(this.authScheme.authenticate(
|
Mockito.when(this.authScheme.authenticate(
|
||||||
|
@ -198,9 +195,7 @@ public class TestRequestAuthenticationBase {
|
||||||
public void testAuthSuccessConnectionBased() throws Exception {
|
public void testAuthSuccessConnectionBased() throws Exception {
|
||||||
HttpRequest request = new BasicHttpRequest("GET", "/");
|
HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||||
this.authState.setState(AuthProtocolState.SUCCESS);
|
this.authState.setState(AuthProtocolState.SUCCESS);
|
||||||
|
this.authState.update(this.authScheme, this.credentials);
|
||||||
this.authState.setAuthScheme(this.authScheme);
|
|
||||||
this.authState.setCredentials(this.credentials);
|
|
||||||
|
|
||||||
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.TRUE);
|
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.TRUE);
|
||||||
Mockito.when(this.authScheme.authenticate(
|
Mockito.when(this.authScheme.authenticate(
|
||||||
|
|
|
@ -85,8 +85,7 @@ public class TestRequestProxyAuthentication {
|
||||||
authscheme.processChallenge(challenge);
|
authscheme.processChallenge(challenge);
|
||||||
|
|
||||||
AuthState authstate = new AuthState();
|
AuthState authstate = new AuthState();
|
||||||
authstate.setAuthScheme(authscheme);
|
authstate.update(authscheme, creds);
|
||||||
authstate.setCredentials(creds);
|
|
||||||
|
|
||||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
||||||
|
@ -118,8 +117,7 @@ public class TestRequestProxyAuthentication {
|
||||||
authscheme.processChallenge(challenge);
|
authscheme.processChallenge(challenge);
|
||||||
|
|
||||||
AuthState authstate = new AuthState();
|
AuthState authstate = new AuthState();
|
||||||
authstate.setAuthScheme(authscheme);
|
authstate.update(authscheme, creds);
|
||||||
authstate.setCredentials(creds);
|
|
||||||
|
|
||||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
||||||
|
@ -151,8 +149,7 @@ public class TestRequestProxyAuthentication {
|
||||||
authscheme.processChallenge(challenge);
|
authscheme.processChallenge(challenge);
|
||||||
|
|
||||||
AuthState authstate = new AuthState();
|
AuthState authstate = new AuthState();
|
||||||
authstate.setAuthScheme(authscheme);
|
authstate.update(authscheme, creds);
|
||||||
authstate.setCredentials(creds);
|
|
||||||
|
|
||||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
||||||
|
@ -239,9 +236,8 @@ public class TestRequestProxyAuthentication {
|
||||||
|
|
||||||
Credentials creds = new UsernamePasswordCredentials("user", "secret");
|
Credentials creds = new UsernamePasswordCredentials("user", "secret");
|
||||||
|
|
||||||
authstate.setAuthScheme(authscheme);
|
|
||||||
authstate.setCredentials(creds);
|
|
||||||
authstate.setState(AuthProtocolState.SUCCESS);
|
authstate.setState(AuthProtocolState.SUCCESS);
|
||||||
|
authstate.update(authscheme, creds);
|
||||||
|
|
||||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.PROXY_AUTH_STATE, authstate);
|
||||||
|
|
|
@ -70,8 +70,7 @@ public class TestRequestTargetAuthentication {
|
||||||
authscheme.processChallenge(challenge);
|
authscheme.processChallenge(challenge);
|
||||||
|
|
||||||
AuthState authstate = new AuthState();
|
AuthState authstate = new AuthState();
|
||||||
authstate.setAuthScheme(authscheme);
|
authstate.update(authscheme, creds);
|
||||||
authstate.setCredentials(creds);
|
|
||||||
|
|
||||||
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
||||||
|
|
||||||
|
@ -93,8 +92,7 @@ public class TestRequestTargetAuthentication {
|
||||||
authscheme.processChallenge(challenge);
|
authscheme.processChallenge(challenge);
|
||||||
|
|
||||||
AuthState authstate = new AuthState();
|
AuthState authstate = new AuthState();
|
||||||
authstate.setAuthScheme(authscheme);
|
authstate.update(authscheme, creds);
|
||||||
authstate.setCredentials(creds);
|
|
||||||
|
|
||||||
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
||||||
|
|
||||||
|
@ -117,8 +115,7 @@ public class TestRequestTargetAuthentication {
|
||||||
authscheme.processChallenge(challenge);
|
authscheme.processChallenge(challenge);
|
||||||
|
|
||||||
AuthState authstate = new AuthState();
|
AuthState authstate = new AuthState();
|
||||||
authstate.setAuthScheme(authscheme);
|
authstate.update(authscheme, creds);
|
||||||
authstate.setCredentials(creds);
|
|
||||||
|
|
||||||
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
||||||
|
|
||||||
|
@ -178,9 +175,8 @@ public class TestRequestTargetAuthentication {
|
||||||
|
|
||||||
Credentials creds = new UsernamePasswordCredentials("user", "secret");
|
Credentials creds = new UsernamePasswordCredentials("user", "secret");
|
||||||
|
|
||||||
authstate.setAuthScheme(authscheme);
|
|
||||||
authstate.setCredentials(creds);
|
|
||||||
authstate.setState(AuthProtocolState.SUCCESS);
|
authstate.setState(AuthProtocolState.SUCCESS);
|
||||||
|
authstate.update(authscheme, creds);
|
||||||
|
|
||||||
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ import org.apache.http.HttpVersion;
|
||||||
import org.apache.http.auth.AUTH;
|
import org.apache.http.auth.AUTH;
|
||||||
import org.apache.http.auth.AuthProtocolState;
|
import org.apache.http.auth.AuthProtocolState;
|
||||||
import org.apache.http.auth.AuthState;
|
import org.apache.http.auth.AuthState;
|
||||||
|
import org.apache.http.auth.Credentials;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
import org.apache.http.client.AuthCache;
|
import org.apache.http.client.AuthCache;
|
||||||
import org.apache.http.impl.auth.BasicScheme;
|
import org.apache.http.impl.auth.BasicScheme;
|
||||||
import org.apache.http.impl.client.BasicAuthCache;
|
import org.apache.http.impl.client.BasicAuthCache;
|
||||||
|
@ -52,6 +54,7 @@ public class TestResponseAuthCache {
|
||||||
private HttpHost proxy;
|
private HttpHost proxy;
|
||||||
private BasicScheme authscheme1;
|
private BasicScheme authscheme1;
|
||||||
private BasicScheme authscheme2;
|
private BasicScheme authscheme2;
|
||||||
|
private Credentials credentials;
|
||||||
private AuthState targetState;
|
private AuthState targetState;
|
||||||
private AuthState proxyState;
|
private AuthState proxyState;
|
||||||
|
|
||||||
|
@ -62,6 +65,7 @@ public class TestResponseAuthCache {
|
||||||
|
|
||||||
this.authscheme1 = new BasicScheme();
|
this.authscheme1 = new BasicScheme();
|
||||||
this.authscheme2 = new BasicScheme();
|
this.authscheme2 = new BasicScheme();
|
||||||
|
this.credentials = new UsernamePasswordCredentials("user", "pwd");
|
||||||
|
|
||||||
this.targetState = new AuthState();
|
this.targetState = new AuthState();
|
||||||
this.proxyState = new AuthState();
|
this.proxyState = new AuthState();
|
||||||
|
@ -91,10 +95,10 @@ public class TestResponseAuthCache {
|
||||||
new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
|
new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
|
||||||
|
|
||||||
this.targetState.setState(AuthProtocolState.CHALLENGED);
|
this.targetState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.targetState.setAuthScheme(this.authscheme1);
|
this.targetState.update(this.authscheme1, this.credentials);
|
||||||
|
|
||||||
this.proxyState.setState(AuthProtocolState.CHALLENGED);
|
this.proxyState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.proxyState.setAuthScheme(this.authscheme2);
|
this.proxyState.update(this.authscheme2, this.credentials);
|
||||||
|
|
||||||
HttpContext context = new BasicHttpContext();
|
HttpContext context = new BasicHttpContext();
|
||||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
||||||
|
@ -148,10 +152,10 @@ public class TestResponseAuthCache {
|
||||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
|
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
|
||||||
|
|
||||||
this.targetState.setState(AuthProtocolState.CHALLENGED);
|
this.targetState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.targetState.setAuthScheme(this.authscheme1);
|
this.targetState.update(this.authscheme1, this.credentials);
|
||||||
|
|
||||||
this.proxyState.setState(AuthProtocolState.CHALLENGED);
|
this.proxyState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.proxyState.setAuthScheme(this.authscheme2);
|
this.proxyState.update(this.authscheme2, this.credentials);
|
||||||
|
|
||||||
HttpContext context = new BasicHttpContext();
|
HttpContext context = new BasicHttpContext();
|
||||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
||||||
|
@ -176,10 +180,10 @@ public class TestResponseAuthCache {
|
||||||
new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
|
new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
|
||||||
|
|
||||||
this.targetState.setState(AuthProtocolState.UNCHALLENGED);
|
this.targetState.setState(AuthProtocolState.UNCHALLENGED);
|
||||||
this.targetState.setAuthScheme(this.authscheme1);
|
this.targetState.update(this.authscheme1, this.credentials);
|
||||||
|
|
||||||
this.proxyState.setState(AuthProtocolState.UNCHALLENGED);
|
this.proxyState.setState(AuthProtocolState.UNCHALLENGED);
|
||||||
this.proxyState.setAuthScheme(this.authscheme2);
|
this.proxyState.update(this.authscheme2, this.credentials);
|
||||||
|
|
||||||
HttpContext context = new BasicHttpContext();
|
HttpContext context = new BasicHttpContext();
|
||||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
||||||
|
@ -206,10 +210,10 @@ public class TestResponseAuthCache {
|
||||||
new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
|
new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=auth-realm"));
|
||||||
|
|
||||||
this.targetState.setState(AuthProtocolState.FAILURE);
|
this.targetState.setState(AuthProtocolState.FAILURE);
|
||||||
this.targetState.setAuthScheme(this.authscheme1);
|
this.targetState.update(this.authscheme1, this.credentials);
|
||||||
|
|
||||||
this.proxyState.setState(AuthProtocolState.FAILURE);
|
this.proxyState.setState(AuthProtocolState.FAILURE);
|
||||||
this.proxyState.setAuthScheme(this.authscheme2);
|
this.proxyState.update(this.authscheme2, this.credentials);
|
||||||
|
|
||||||
HttpContext context = new BasicHttpContext();
|
HttpContext context = new BasicHttpContext();
|
||||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
||||||
|
|
|
@ -248,8 +248,7 @@ public class TestHttpAuthenticator {
|
||||||
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
||||||
|
|
||||||
this.authState.setState(AuthProtocolState.CHALLENGED);
|
this.authState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.authState.setAuthScheme(new BasicScheme());
|
this.authState.update(new BasicScheme(), this.credentials);
|
||||||
this.authState.setCredentials(this.credentials);
|
|
||||||
|
|
||||||
Assert.assertFalse(this.httpAuthenticator.authenticate(host,
|
Assert.assertFalse(this.httpAuthenticator.authenticate(host,
|
||||||
response, authStrategy, this.authState, this.context));
|
response, authStrategy, this.authState, this.context));
|
||||||
|
@ -268,8 +267,7 @@ public class TestHttpAuthenticator {
|
||||||
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
||||||
|
|
||||||
this.authState.setState(AuthProtocolState.CHALLENGED);
|
this.authState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.authState.setAuthScheme(new DigestScheme());
|
this.authState.update(new DigestScheme(), this.credentials);
|
||||||
this.authState.setCredentials(this.credentials);
|
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.authenticate(host,
|
Assert.assertTrue(this.httpAuthenticator.authenticate(host,
|
||||||
response, authStrategy, this.authState, this.context));
|
response, authStrategy, this.authState, this.context));
|
||||||
|
@ -286,8 +284,7 @@ public class TestHttpAuthenticator {
|
||||||
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
||||||
|
|
||||||
this.authState.setState(AuthProtocolState.CHALLENGED);
|
this.authState.setState(AuthProtocolState.CHALLENGED);
|
||||||
this.authState.setAuthScheme(new BasicScheme());
|
this.authState.update(new BasicScheme(), this.credentials);
|
||||||
this.authState.setCredentials(this.credentials);
|
|
||||||
|
|
||||||
Assert.assertTrue(this.httpAuthenticator.authenticate(host,
|
Assert.assertTrue(this.httpAuthenticator.authenticate(host,
|
||||||
response, authStrategy, this.authState, this.context));
|
response, authStrategy, this.authState, this.context));
|
||||||
|
|
Loading…
Reference in New Issue