Java 类org.apache.http.impl.auth.NTLMScheme 实例源码

项目:purecloud-iot    文件:TestBasicAuthCache.java   
@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)));
}
项目:orbeon-forms    文件:PreemptiveAuthHttpRequestInterceptor.java   
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);
        }
    }
}
项目:gradle-download-task    文件:AuthenticationTest.java   
/**
 * 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();
}
项目:Reer    文件:NTLMSchemeFactory.java   
@Override
public AuthScheme create(HttpContext context) {
    return new NTLMScheme(new JCIFSEngine());
}
项目:purecloud-iot    文件:TestMainClientExec.java   
@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());
}
项目:purecloud-iot    文件:TestRedirectExec.java   
@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());
}
项目:Pushjet-Android    文件:NTLMSchemeFactory.java   
public AuthScheme newInstance(HttpParams params) {
    return new NTLMScheme(new JCIFSEngine());
}
项目:Pushjet-Android    文件:NTLMSchemeFactory.java   
public AuthScheme newInstance(HttpParams params) {
    return new NTLMScheme(new JCIFSEngine());
}
项目:taskerbox    文件:NTLMSchemeFactory.java   
@Override
public AuthScheme newInstance(final HttpParams params) {
    return new NTLMScheme(new JCIFSEngine());
  }
项目:cleverbus    文件:NTLMSchemeFactory.java   
@Override
public AuthScheme create(HttpContext httpContext) {
    return new NTLMScheme(new JCIFSEngine());
}
项目:jntlm    文件:NTLMSchemeProvider.java   
public AuthScheme create(HttpContext context) {
    return new NTLMScheme(new SSONTLMEngine());
}
项目:iaf    文件:WebServiceNtlmSender.java   
public AuthScheme newInstance(final HttpParams params) {
    return new NTLMScheme(new JCIFSEngine());
}
项目:opensearchserver    文件:NTLMSchemeFactory.java   
@Override
public AuthScheme create(final HttpContext context) {
    return new NTLMScheme(new JCIFSEngine());
}