Package org.apache.http.impl.auth

Examples of org.apache.http.impl.auth.BasicScheme


        // for dealing with automatic authentication
        if (authType == AuthType.NTLM) {
            // todo: not supported yet
            //ctx.setAttribute("preemptive-auth", new NTLMScheme(new JCIFSEngine()));
        } else if (authType == AuthType.BASIC) {
            ctx.setAttribute("preemptive-auth", new BasicScheme());
        }

        StatusLine statusLine = null;
        try {
            // set the User-Agent if it's not already set
View Full Code Here


            int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;

            client.getCredentialsProvider().setCredentials( new AuthScope( host, port ), creds );

            AuthCache authCache = new BasicAuthCache();
            BasicScheme basicAuth = new BasicScheme();
            HttpHost targetHost = new HttpHost( repository.getHost(), repository.getPort(), repository.getProtocol() );
            authCache.put( targetHost, basicAuth );

            localContext = new BasicHttpContext();
            localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
View Full Code Here

                else
                {
                    creds = new UsernamePasswordCredentials( proxyInfo.getUserName(), proxyInfo.getPassword() );
                }

                Header bs = new BasicScheme().authenticate( creds, httpMethod );
                httpMethod.addHeader( "Proxy-Authorization", bs.getValue() );
            }

        }
View Full Code Here

        final AuthScope scope = ((PreemptiveAuthHttpRequestFactory) getRestTemplate().getRequestFactory()).
                getAuthScope();
        final HttpHost targetHost = new HttpHost(scope.getHost(), scope.getPort(), scope.getScheme());
        final BasicHttpContext localcontext = new BasicHttpContext();
        final AuthCache authCache = new BasicAuthCache();
        authCache.put(targetHost, new BasicScheme());
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        final HttpGet getMethod = new HttpGet(url);
        try {
            final HttpResponse httpResponse =
View Full Code Here

      // Preemptive authentication enabled - see
      // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d5e1032
      HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());
      AuthCache authCache = new BasicAuthCache();
      BasicScheme basicAuth = new BasicScheme();
      authCache.put(targetHost, basicAuth);
      BasicHttpContext localcontext = new BasicHttpContext();
      localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

      HttpResponse response = httpclient.execute(method, localcontext);
View Full Code Here

        // Add AuthCache to the execution context
        BasicHttpContext localcontext = new BasicHttpContext();

        // Generate BASIC scheme object and add it to the local auth cache
        AuthCache authCache = new BasicAuthCache();
        authCache.put(targetHost, new BasicScheme());
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        return localcontext;
    }
View Full Code Here

        Mockito.when(connRequest.get(
                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(managedConn);
        final Map<String, Header> challenges = new HashMap<String, Header>();
        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
        final AuthOption authOption = new AuthOption(
                new BasicScheme(), new UsernamePasswordCredentials("user:pass"));
        Mockito.when(targetAuthStrategy.getChallenges(
                Mockito.eq(target),
                Mockito.<HttpResponse>any(),
                Mockito.<HttpClientContext>any())).thenReturn(challenges);
        Mockito.when(targetAuthStrategy.getChallenges(
View Full Code Here

        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"));
        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState);
        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
View Full Code Here

        this.credProvider = new BasicCredentialsProvider();
        this.creds1 = new UsernamePasswordCredentials("user1", "secret1");
        this.creds2 = new UsernamePasswordCredentials("user2", "secret2");
        this.authscope1 = new AuthScope(this.target);
        this.authscope2 = new AuthScope(this.proxy);
        this.authscheme1 = new BasicScheme();
        this.authscheme2 = new BasicScheme();

        this.credProvider.setCredentials(this.authscope1, this.creds1);
        this.credProvider.setCredentials(this.authscope2, this.creds2);

        this.targetState = new AuthState();
View Full Code Here

        authCache.put(this.proxy, this.authscheme2);

        context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

        this.targetState.setState(AuthProtocolState.CHALLENGED);
        this.targetState.update(new BasicScheme(), new UsernamePasswordCredentials("user3", "secret3"));
        this.proxyState.setState(AuthProtocolState.CHALLENGED);
        this.proxyState.update(new BasicScheme(), new UsernamePasswordCredentials("user4", "secret4"));

        final HttpRequestInterceptor interceptor = new RequestAuthCache();
        interceptor.process(request, context);
        Assert.assertNotSame(this.authscheme1, this.targetState.getAuthScheme());
        Assert.assertNotSame(this.creds1, this.targetState.getCredentials());
View Full Code Here

TOP

Related Classes of org.apache.http.impl.auth.BasicScheme

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.