Package org.apache.http.client

Examples of org.apache.http.client.CredentialsProvider


        return hdrs.toString();
    }

    private void setConnectionAuthorization(HttpClient client, URL url, AuthManager authManager) {
        CredentialsProvider credentialsProvider =
            ((AbstractHttpClient) client).getCredentialsProvider();
        if (authManager != null) {
            Authorization auth = authManager.getAuthForURL(url);
            if (auth != null) {
                    String username = auth.getUser();
                    String realm = auth.getRealm();
                    String domain = auth.getDomain();
                    if (log.isDebugEnabled()){
                        log.debug(username + " > D="+domain+" R="+realm);
                    }
                    credentialsProvider.setCredentials(
                            new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
                            new NTCredentials(username, auth.getPass(), localHost, domain));
            } else {
                credentialsProvider.clear();
            }
        } else {
            credentialsProvider.clear();           
        }
    }
View Full Code Here


            }
           
            BasicHttpContext ctx = new BasicHttpContext();
            if (AsyncHTTPConduit.this.proxyAuthorizationPolicy != null
                && AsyncHTTPConduit.this.proxyAuthorizationPolicy.getUserName() != null) {
                ctx.setAttribute(ClientContext.CREDS_PROVIDER, new CredentialsProvider() {
                    public void setCredentials(AuthScope authscope, Credentials credentials) {
                    }
                    public Credentials getCredentials(AuthScope authscope) {
                        return new UsernamePasswordCredentials(AsyncHTTPConduit.this
                                                               .proxyAuthorizationPolicy.getUserName(),
                                               AsyncHTTPConduit.this.proxyAuthorizationPolicy.getPassword());
                    }
                    public void clear() {
                    }
                });
            }
            if (tlsClientParameters != null && tlsClientParameters.hashCode() == lastTlsHash && sslState != null) {
                ctx.setAttribute(ClientContext.USER_TOKEN , sslState);
            }
           
            final AsyncSchemeRegistry reg = new AsyncSchemeRegistry();
            reg.register(new AsyncScheme("http", 80, null));
            if ("https".equals(url.getScheme())) {
                try {
                    final SSLContext sslcontext = getSSLContext();
                    reg.register(new AsyncScheme("https", 443, new SSLLayeringStrategy(sslcontext) {
                        @Override
                        protected void initializeEngine(SSLEngine engine) {
                            initializeSSLEngine(sslcontext, engine);
                        }
                        @Override
                        protected void verifySession(final IOSession iosession,
                                              final SSLSession sslsession) throws SSLException {
                            super.verifySession(iosession, sslsession);
                            iosession.setAttribute("cxf.handshake.done", Boolean.TRUE);
                            CXFHttpRequest req = (CXFHttpRequest)iosession
                                .removeAttribute(CXFHttpRequest.class.getName());
                            if (req != null) {
                                req.getOutputStream().setSSLSession(sslsession);
                            }
                        }
                    }));
                } catch (GeneralSecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            ctx.setAttribute(ClientContext.SCHEME_REGISTRY, reg);
            connectionFuture = new BasicFuture<Boolean>(callback);
            DefaultHttpAsyncClient c = getHttpAsyncClient();
            CredentialsProvider credProvider = c.getCredentialsProvider();
            Credentials creds = (Credentials)outMessage.getContextualProperty(Credentials.class.getName());
            if (creds != null && credProvider != null) {
                credProvider.setCredentials(AuthScope.ANY, creds);
            }
            if (credProvider != null && credProvider.getCredentials(AuthScope.ANY) != null) {
                ctx.setAttribute(ClientContext.USER_TOKEN,
                                 credProvider.getCredentials(AuthScope.ANY).getUserPrincipal());
            }
           
            c.execute(new CXFHttpAsyncRequestProducer(entity, outbuf),
                      new CXFHttpAsyncResponseConsumer(this, inbuf, responseCallback),
                      ctx,
View Full Code Here

            if (followup != null) {
                return followup;
            }
        }
        if (HttpClientParams.isAuthenticating(this.params)) {
            CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute(
                    ClientContext.CREDS_PROVIDER);
            if (credsProvider != null) {
                followup = handleTargetChallenge(credsProvider);
                if (followup != null) {
                    return followup;
View Full Code Here

    }

    private RoutedRequest handleConnectResponse() throws HttpException {
        RoutedRequest followup = null;
        if (HttpClientParams.isAuthenticating(this.params)) {
            CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute(
                    ClientContext.CREDS_PROVIDER);
            if (credsProvider != null) {
                followup = handleProxyChallenge(credsProvider);
                if (followup != null) {
                    return followup;
View Full Code Here

            if (status < 200) {
                throw new HttpException("Unexpected response to CONNECT request: " +
                        response.getStatusLine());
            }
           
            CredentialsProvider credsProvider = (CredentialsProvider)
                context.getAttribute(ClientContext.CREDS_PROVIDER);
           
            if (credsProvider != null && HttpClientParams.isAuthenticating(params)) {
                if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
View Full Code Here

            }
           
            return newRequest;
        }

        CredentialsProvider credsProvider = (CredentialsProvider)
            context.getAttribute(ClientContext.CREDS_PROVIDER);
   
        if (credsProvider != null && HttpClientParams.isAuthenticating(params)) {

            if (this.targetAuthHandler.isAuthenticationRequested(response, context)) {
View Full Code Here

            }
           
            // Be careful to scope credentials to the specific URI so that HttpClient won't try
            // and send them to other servers
            HttpHost host = new HttpHost(uri.getHost(), uri.getPort());
            CredentialsProvider provider = new BasicCredentialsProvider();
           
            String user = context.getAttribute(Service.queryAuthUser.toString()).toString();
            String pwd = context.getAttribute(Service.queryAuthPwd.toString()).toString();
            provider.setCredentials(new AuthScope(host), new UsernamePasswordCredentials(user, pwd));
        }
    }
View Full Code Here

            // If no auth scheme avaialble yet, try to initialize it preemptively
            if( authState.getAuthScheme() == null ) {
                AuthScheme authScheme = (AuthScheme) context.getAttribute(
                    "preemptive-auth" );
                CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
                    ClientContext.CREDS_PROVIDER );
                HttpHost targetHost = (HttpHost) context.getAttribute(
                    ExecutionContext.HTTP_TARGET_HOST );
                if( authScheme != null ) {
                    Credentials creds = credsProvider.getCredentials(
                        new AuthScope(
                        targetHost.getHostName(),
                        targetHost.getPort() ) );
                    if( creds == null ) {
                        throw new HttpException( "No credentials for preemptive authentication" );
View Full Code Here

            AuthState authState = (AuthState) context.getAttribute( ClientContext.TARGET_AUTH_STATE );

            // If no auth scheme avaialble yet, try to initialize it preemptively
            if( authState.getAuthScheme() == null ) {
                AuthScheme authScheme = (AuthScheme) context.getAttribute( "preemptive-auth" );
                CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute( ClientContext.CREDS_PROVIDER );
//                HttpHost targetHost = (HttpHost) context.getAttribute( ExecutionContext.HTTP_TARGET_HOST );
                if( authScheme != null ) {
                    Credentials creds = credsProvider.getCredentials( AuthScope.ANY );
                    if( creds == null ) {
                        throw new HttpException( "No credentials for preemptive authentication" );
                    }
                    authState.setAuthScheme( authScheme );
                    authState.setCredentials( creds );
View Full Code Here

    public void test(
            @ArquillianResource(SecureServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1,
            @ArquillianResource(SecureServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2)
            throws IOException, URISyntaxException {

        CredentialsProvider provider = new BasicCredentialsProvider();
        HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();

        URI uri1 = SecureServlet.createURI(baseURL1);
        URI uri2 = SecureServlet.createURI(baseURL2);
View Full Code Here

TOP

Related Classes of org.apache.http.client.CredentialsProvider

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.