本文整理汇总了Java中org.apache.http.auth.AuthProtocolState类的典型用法代码示例。如果您正苦于以下问题:Java AuthProtocolState类的具体用法?Java AuthProtocolState怎么用?Java AuthProtocolState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthProtocolState类属于org.apache.http.auth包,在下文中一共展示了AuthProtocolState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPreemptiveAuth
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final AuthState authState,
final CredentialsProvider credsProvider) {
String schemeName = authScheme.getSchemeName();
if (this.log.isDebugEnabled()) {
this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
}
AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName);
Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setState(AuthProtocolState.SUCCESS);
authState.update(authScheme, creds);
} else {
this.log.debug("No credentials for preemptive authentication");
}
}
示例2: isAuthenticationRequested
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
public boolean isAuthenticationRequested(
final HttpHost host,
final HttpResponse response,
final AuthenticationStrategy authStrategy,
final AuthState authState,
final HttpContext context) {
if (authStrategy.isAuthenticationRequested(host, response, context)) {
return true;
} else {
switch (authState.getState()) {
case CHALLENGED:
case HANDSHAKE:
authState.setState(AuthProtocolState.SUCCESS);
authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
break;
case SUCCESS:
break;
default:
authState.setState(AuthProtocolState.UNCHALLENGED);
}
return false;
}
}
示例3: doPreemptiveAuth
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final AuthStateHC4 authState,
final CredentialsProvider credsProvider) {
final String schemeName = authScheme.getSchemeName();
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Re-using cached '" + schemeName + "' auth scheme for " + host);
}
final AuthScope authScope = new AuthScope(host.getHostName(), host.getPort(), AuthScope.ANY_REALM, schemeName);
final Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
authState.setState(AuthProtocolState.CHALLENGED);
} else {
authState.setState(AuthProtocolState.SUCCESS);
}
authState.update(authScheme, creds);
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "No credentials for preemptive authentication");
}
}
}
示例4: buildHttpContext
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
/**
* Builds a configured HTTP context object that is pre-configured for
* using HTTP Signature authentication.
*
* @param configurator HTTP Signatures configuration helper to pull properties from
* @return configured HTTP context object
*/
protected HttpContext buildHttpContext(final HttpSignatureConfigurator configurator) {
final HttpClientContext context = HttpClientContext.create();
if (configurator != null) {
AuthCache authCache = new BasicAuthCache();
context.setAuthCache(authCache);
AuthState authState = new AuthState();
authState.update(configurator.getAuthScheme(), configurator.getCredentials());
context.setAttribute(HttpClientContext.TARGET_AUTH_STATE,
authState);
context.getTargetAuthState().setState(AuthProtocolState.UNCHALLENGED);
}
return context;
}
示例5: doPreemptiveAuth
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final AuthState authState,
final CredentialsProvider credsProvider) {
final String schemeName = authScheme.getSchemeName();
if (this.log.isDebugEnabled()) {
this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
}
final AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName);
final Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
authState.setState(AuthProtocolState.CHALLENGED);
} else {
authState.setState(AuthProtocolState.SUCCESS);
}
authState.update(authScheme, creds);
} else {
this.log.debug("No credentials for preemptive authentication");
}
}
示例6: testAuthenticationRequestedAfterSuccess
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
public void testAuthenticationRequestedAfterSuccess() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
Mockito.any(HttpHost.class),
Mockito.any(HttpResponse.class),
Mockito.any(HttpContext.class))).thenReturn(Boolean.TRUE);
this.authState.update(this.authScheme, this.credentials);
this.authState.setState(AuthProtocolState.SUCCESS);
Assert.assertTrue(this.httpAuthenticator.isAuthenticationRequested(
this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
Mockito.verify(this.defltAuthStrategy).authFailed(this.defaultHost, this.authScheme, this.context);
}
示例7: testAuthenticationNotRequestedSuccess1
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
public void testAuthenticationNotRequestedSuccess1() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
Mockito.any(HttpHost.class),
Mockito.any(HttpResponse.class),
Mockito.any(HttpContext.class))).thenReturn(Boolean.FALSE);
this.authState.update(this.authScheme, this.credentials);
this.authState.setState(AuthProtocolState.CHALLENGED);
Assert.assertFalse(this.httpAuthenticator.isAuthenticationRequested(
this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.SUCCESS, this.authState.getState());
Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
Mockito.verify(this.defltAuthStrategy).authSucceeded(this.defaultHost, this.authScheme, this.context);
}
示例8: testAuthenticationNotRequestedSuccess2
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
public void testAuthenticationNotRequestedSuccess2() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
Mockito.any(HttpHost.class),
Mockito.any(HttpResponse.class),
Mockito.any(HttpContext.class))).thenReturn(Boolean.FALSE);
this.authState.update(this.authScheme, this.credentials);
this.authState.setState(AuthProtocolState.HANDSHAKE);
Assert.assertFalse(this.httpAuthenticator.isAuthenticationRequested(
this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.SUCCESS, this.authState.getState());
Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
Mockito.verify(this.defltAuthStrategy).authSucceeded(this.defaultHost, this.authScheme, this.context);
}
示例9: testAuthentication
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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\""));
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(host,
response, authStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
final Queue<AuthOption> options = this.authState.getAuthOptions();
Assert.assertNotNull(options);
final AuthOption option1 = options.poll();
Assert.assertNotNull(option1);
Assert.assertEquals("digest", option1.getAuthScheme().getSchemeName());
final AuthOption option2 = options.poll();
Assert.assertNotNull(option2);
Assert.assertEquals("basic", option2.getAuthScheme().getSchemeName());
Assert.assertNull(options.poll());
}
示例10: testAuthenticationFailed
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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\""));
this.authState.setState(AuthProtocolState.CHALLENGED);
this.authState.update(this.authScheme, this.credentials);
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
response, authStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
Mockito.verify(this.authCache).remove(host);
}
示例11: testAuthenticationFailedPreviously
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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\""));
this.authState.setState(AuthProtocolState.FAILURE);
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
response, authStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
}
示例12: testAuthenticationFailure
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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\""));
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
this.authState.setState(AuthProtocolState.CHALLENGED);
this.authState.update(new BasicScheme(), this.credentials);
Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
response, authStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
Assert.assertNull(this.authState.getCredentials());
}
示例13: testAuthenticationHandshaking
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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\""));
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
this.authState.setState(AuthProtocolState.CHALLENGED);
this.authState.update(new DigestScheme(), this.credentials);
Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(host,
response, authStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.HANDSHAKE, this.authState.getState());
}
示例14: testAuthenticationNoMatchingChallenge
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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\""));
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
this.authState.setState(AuthProtocolState.CHALLENGED);
this.authState.update(new BasicScheme(), this.credentials);
Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(host,
response, authStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
final Queue<AuthOption> options = this.authState.getAuthOptions();
Assert.assertNotNull(options);
final AuthOption option1 = options.poll();
Assert.assertNotNull(option1);
Assert.assertEquals("digest", option1.getAuthScheme().getSchemeName());
Assert.assertNull(options.poll());
}
示例15: testAuthenticationException
import org.apache.http.auth.AuthProtocolState; //导入依赖的package包/类
@Test
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");
this.authState.setState(AuthProtocolState.CHALLENGED);
Mockito.doThrow(new MalformedChallengeException()).when(this.defltAuthStrategy).getChallenges(
Mockito.any(HttpHost.class),
Mockito.any(HttpResponse.class),
Mockito.any(HttpContext.class));
Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
response, this.defltAuthStrategy, this.authState, this.context));
Assert.assertEquals(AuthProtocolState.UNCHALLENGED, this.authState.getState());
Assert.assertNull(this.authState.getAuthScheme());
Assert.assertNull(this.authState.getCredentials());
}