本文整理汇总了Java中org.apache.http.impl.auth.NTLMScheme类的典型用法代码示例。如果您正苦于以下问题:Java NTLMScheme类的具体用法?Java NTLMScheme怎么用?Java NTLMScheme使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NTLMScheme类属于org.apache.http.impl.auth包,在下文中一共展示了NTLMScheme类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStoreNonserializable
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Test
public void testStoreNonserializable() throws Exception {
final BasicAuthCache cache = new BasicAuthCache();
final AuthScheme authScheme = new NTLMScheme();
cache.put(new HttpHost("localhost", 80), authScheme);
Assert.assertNull(cache.get(new HttpHost("localhost", 80)));
}
示例2: process
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
// If not auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
// Obtain credentials matching the target host
Credentials credentials = credentialsProvider.getCredentials(authScope);
// If found, generate BasicScheme preemptively
if (credentials != null) {
authState.setAuthScheme(credentials instanceof NTCredentials ? new NTLMScheme(new JCIFSEngine()) : new BasicScheme());
authState.setCredentials(credentials);
}
}
}
示例3: invalidAuthSchemeWithUserAndPass
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
/**
* Make sure the plugin rejects an invalid authentication scheme if
* username and password are set
* @throws Exception if anything goes wrong
*/
@Test(expected = TaskExecutionException.class)
public void invalidAuthSchemeWithUserAndPass() throws Exception {
Download t = makeProjectAndTask();
t.src(makeSrc(AUTHENTICATE));
File dst = folder.newFile();
t.dest(dst);
t.username(USERNAME);
t.password(PASSWORD);
t.authScheme(new NTLMScheme());
t.execute();
}
示例4: create
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Override
public AuthScheme create(HttpContext context) {
return new NTLMScheme(new JCIFSEngine());
}
示例5: testExecEntityEnclosingRequestRetryOnAuthChallenge
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Test
public void testExecEntityEnclosingRequestRetryOnAuthChallenge() throws Exception {
final HttpRoute route = new HttpRoute(target);
final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
final HttpResponse response1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 401, "Huh?");
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
response1.setEntity(EntityBuilder.create()
.setStream(instream1)
.build());
final HttpResponse response2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
response2.setEntity(EntityBuilder.create()
.setStream(instream2)
.build());
final AuthState proxyAuthState = new AuthState();
proxyAuthState.setState(AuthProtocolState.SUCCESS);
proxyAuthState.update(new NTLMScheme(), new NTCredentials("user:pass"));
final HttpClientContext context = new HttpClientContext();
context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
Mockito.when(managedConn.isOpen()).thenReturn(Boolean.TRUE);
Mockito.when(managedConn.isStale()).thenReturn(Boolean.FALSE);
Mockito.when(requestExecutor.execute(
Mockito.same(request),
Mockito.<HttpClientConnection>any(),
Mockito.<HttpClientContext>any())).thenReturn(response1, response2);
Mockito.when(reuseStrategy.keepAlive(
Mockito.<HttpResponse>any(),
Mockito.<HttpClientContext>any())).thenReturn(Boolean.FALSE);
Mockito.when(targetAuthStrategy.isAuthenticationRequested(
Mockito.eq(target),
Mockito.same(response1),
Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
final CloseableHttpResponse finalResponse = mainClientExec.execute(
route, request, context, execAware);
Mockito.verify(requestExecutor, Mockito.times(2)).execute(request, managedConn, context);
Mockito.verify(managedConn).close();
Mockito.verify(instream2, Mockito.never()).close();
Assert.assertNotNull(finalResponse);
Assert.assertEquals(200, finalResponse.getStatusLine().getStatusCode());
Assert.assertNull(proxyAuthState.getAuthScheme());
Assert.assertNull(proxyAuthState.getCredentials());
}
示例6: testCrossSiteRedirect
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Test
public void testCrossSiteRedirect() throws Exception {
final HttpRoute route = new HttpRoute(target);
final HttpGet get = new HttpGet("/test");
final HttpRequestWrapper request = HttpRequestWrapper.wrap(get);
final HttpClientContext context = HttpClientContext.create();
final AuthState targetAuthState = new AuthState();
targetAuthState.setState(AuthProtocolState.SUCCESS);
targetAuthState.update(new BasicScheme(), new UsernamePasswordCredentials("user", "pass"));
final AuthState proxyAuthState = new AuthState();
proxyAuthState.setState(AuthProtocolState.SUCCESS);
proxyAuthState.update(new NTLMScheme(), new NTCredentials("user", "pass", null, null));
context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState);
context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
final CloseableHttpResponse response1 = Mockito.mock(CloseableHttpResponse.class);
final CloseableHttpResponse response2 = Mockito.mock(CloseableHttpResponse.class);
final HttpGet redirect = new HttpGet("http://otherhost/redirect");
Mockito.when(requestExecutor.execute(
Mockito.eq(route),
Mockito.same(request),
Mockito.<HttpClientContext>any(),
Mockito.<HttpExecutionAware>any())).thenReturn(response1);
Mockito.when(requestExecutor.execute(
Mockito.eq(route),
HttpRequestWrapperMatcher.same(redirect),
Mockito.<HttpClientContext>any(),
Mockito.<HttpExecutionAware>any())).thenReturn(response2);
Mockito.when(redirectStrategy.isRedirected(
Mockito.same(get),
Mockito.same(response1),
Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
Mockito.when(redirectStrategy.getRedirect(
Mockito.same(get),
Mockito.same(response1),
Mockito.<HttpClientContext>any())).thenReturn(redirect);
Mockito.when(httpRoutePlanner.determineRoute(
Mockito.eq(target),
Mockito.<HttpRequestWrapper>any(),
Mockito.<HttpClientContext>any())).thenReturn(new HttpRoute(new HttpHost("otherhost", 80)));
redirectExec.execute(route, request, context, execAware);
Assert.assertNotNull(context.getTargetAuthState());
Assert.assertEquals(AuthProtocolState.UNCHALLENGED, context.getTargetAuthState().getState());
Assert.assertEquals(null, context.getTargetAuthState().getAuthScheme());
Assert.assertNotNull(context.getProxyAuthState());
Assert.assertEquals(AuthProtocolState.UNCHALLENGED, context.getProxyAuthState().getState());
Assert.assertEquals(null, context.getProxyAuthState().getAuthScheme());
}
示例7: newInstance
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
public AuthScheme newInstance(HttpParams params) {
return new NTLMScheme(new JCIFSEngine());
}
示例8: newInstance
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Override
public AuthScheme newInstance(final HttpParams params) {
return new NTLMScheme(new JCIFSEngine());
}
示例9: create
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Override
public AuthScheme create(HttpContext httpContext) {
return new NTLMScheme(new JCIFSEngine());
}
示例10: create
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
public AuthScheme create(HttpContext context) {
return new NTLMScheme(new SSONTLMEngine());
}
示例11: newInstance
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
public AuthScheme newInstance(final HttpParams params) {
return new NTLMScheme(new JCIFSEngine());
}
示例12: create
import org.apache.http.impl.auth.NTLMScheme; //导入依赖的package包/类
@Override
public AuthScheme create(final HttpContext context) {
return new NTLMScheme(new JCIFSEngine());
}