Package org.asynchttpclient

Examples of org.asynchttpclient.Realm$RealmBuilder


            }
        }
    }

    private void addAuthorizationHeader(final Request request, final HttpRequestPacket requestPacket) {
        Realm realm = request.getRealm();
        if (realm == null) {
            realm = config.getRealm();
        }
        if (realm != null && realm.getUsePreemptiveAuth()) {
            final String authHeaderValue = generateAuthHeader(realm);
            if (authHeaderValue != null) {
                requestPacket.addHeader(Header.Authorization, authHeaderValue);
            }
        }
View Full Code Here


        final String auth = responsePacket.getHeader(Header.WWWAuthenticate);
        if (auth == null) {
            throw new IllegalStateException("401 response received, but no WWW-Authenticate header was present");
        }

        Realm realm = httpTransactionContext.getRequest().getRealm();
        if (realm == null) {
            realm = httpTransactionContext.getProvider().getClientConfig().getRealm();
        }
        if (realm == null) {
            httpTransactionContext.setInvocationStatus(STOP);
            if (httpTransactionContext.getHandler() != null) {
                try {
                    httpTransactionContext.getHandler().onStatusReceived(httpTransactionContext.getResponseStatus());
                } catch (Exception e) {
                    httpTransactionContext.abort(e);
                }
            }
            return true;
        }

        responsePacket.setSkipRemainder(true); // ignore the remainder of the response

        final Request req = httpTransactionContext.getRequest();
        realm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(req.getUri())
                .setMethodName(req.getMethod()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(auth).build();
        String lowerCaseAuth = auth.toLowerCase(Locale.ENGLISH);
        if (lowerCaseAuth.startsWith("basic")) {
            req.getHeaders().remove(Header.Authorization.toString());
            req.getHeaders().add(Header.Authorization.toString(), AuthenticatorUtils.computeBasicAuthentication(realm));
View Full Code Here

        final Request req = httpTransactionContext.getRequest();
        ProxyServer proxyServer = httpTransactionContext.getProvider().getClientConfig().getProxyServerSelector()
                .select(req.getUri());
        String principal = proxyServer.getPrincipal();
        String password = proxyServer.getPassword();
        Realm realm = new Realm.RealmBuilder().setPrincipal(principal).setPassword(password).setUri(req.getUri()).setOmitQuery(true)
                .setMethodName(Method.CONNECT.getMethodString()).setUsePreemptiveAuth(true).parseProxyAuthenticateHeader(proxyAuth).build();
        String proxyAuthLowerCase = proxyAuth.toLowerCase(Locale.ENGLISH);
        if (proxyAuthLowerCase.startsWith("basic")) {
            req.getHeaders().remove(Header.ProxyAuthenticate.toString());
            req.getHeaders().remove(Header.ProxyAuthorization.toString());
View Full Code Here

            }
        }
    }

    private Realm getRealm(final Request request) {
        Realm realm = request.getRealm();
        if (realm == null) {
            realm = config.getRealm();
        }
        return realm;
    }
View Full Code Here

             * We need to make sure we aren't in the middle of an authorization
             * process before publishing events as we will re-publish again the
             * same event after the authorization, causing unpredictable
             * behavior.
             */
            Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : config.getRealm();
            boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth();

            if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) {
                ProgressAsyncHandler<?> progressAsyncHandler = (ProgressAsyncHandler<?>) asyncHandler;
                if (notifyHeaders) {
                    progressAsyncHandler.onHeaderWriteCompleted();
View Full Code Here

        boolean useSSl = isSecure(uri) && !useProxy;

        // some headers are only set when performing the first request
        HttpHeaders headers = future.getNettyRequest().getHttpRequest().headers();
        Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();
        HttpMethod method = future.getNettyRequest().getHttpRequest().getMethod();
        requestFactory.addAuthorizationHeader(headers, requestFactory.firstRequestOnlyAuthorizationHeader(request, uri, proxy, realm));
        requestFactory.setProxyAuthorizationHeader(headers, requestFactory.firstRequestOnlyProxyAuthorizationHeader(request, proxy, method));

        // Do not throw an exception when we need an extra connection for a
View Full Code Here

        }

        if (!headers.contains(HttpHeaders.Names.HOST))
            headers.set(HttpHeaders.Names.HOST,  hostHeader(request, uri));

        Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();

        // don't override authorization but append
        addAuthorizationHeader(headers, systematicAuthorizationHeader(request, uri, proxyServer, realm));

        setProxyAuthorizationHeader(headers, systematicProxyAuthorizationHeader(request, proxyServer, method));
View Full Code Here

            List<String> wwwAuthHeaders = response.headers().getAll(HttpHeaders.Names.WWW_AUTHENTICATE);

            if (!wwwAuthHeaders.isEmpty()) {
                future.setState(NettyResponseFuture.STATE.NEW);
                Realm newRealm = null;
                boolean negociate = wwwAuthHeaders.contains("Negotiate");
                String ntlmAuthenticate = getNTLM(wwwAuthHeaders);
                if (!wwwAuthHeaders.contains("Kerberos") && ntlmAuthenticate != null) {
                    // NTLM
                    newRealm = ntlmChallenge(ntlmAuthenticate, request, proxyServer, request.getHeaders(), realm, future, false);

                    // don't forget to reuse channel: NTLM authenticates a connection
                    future.setReuseChannel(true);

                } else if (negociate) {
                    newRealm = kerberosChallenge(channel, wwwAuthHeaders, request, proxyServer, request.getHeaders(), realm, future, false);
                    // SPNEGO KERBEROS
                    if (newRealm == null)
                        return true;
                    else
                        // don't forget to reuse channel: KERBEROS authenticates a connection
                        future.setReuseChannel(true);

                } else {
                    newRealm = new Realm.RealmBuilder()//
                            .clone(realm)//
                            .setScheme(realm.getAuthScheme())//
                            .setUri(request.getUri())//
                            .setMethodName(request.getMethod())//
                            .setUsePreemptiveAuth(true)//
                            .parseWWWAuthenticateHeader(wwwAuthHeaders.get(0))//
                            .build();
                }

                Realm nr = newRealm;
                final Request nextRequest = new RequestBuilder(future.getRequest()).setHeaders(request.getHeaders()).setRealm(nr).build();

                logger.debug("Sending authentication to {}", request.getUri());
                Callback callback = new Callback(future) {
                    public void call() throws IOException {
View Full Code Here

            if (!proxyAuthHeaders.isEmpty()) {
                logger.debug("Sending proxy authentication to {}", request.getUri());

                future.setState(NettyResponseFuture.STATE.NEW);
                Realm newRealm = null;
                FluentCaseInsensitiveStringsMap requestHeaders = request.getHeaders();

                boolean negociate = proxyAuthHeaders.contains("Negotiate");
                String ntlmAuthenticate = getNTLM(proxyAuthHeaders);
                if (!proxyAuthHeaders.contains("Kerberos") && ntlmAuthenticate != null) {
View Full Code Here

        future.setKeepAlive(connectionStrategy.keepAlive(httpRequest, response));

        NettyResponseStatus status = new NettyResponseStatus(future.getUri(), config, response);
        int statusCode = response.getStatus().code();
        Request request = future.getRequest();
        Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();
        NettyResponseHeaders responseHeaders = new NettyResponseHeaders(response.headers());

        return exitAfterProcessingFilters(channel, future, handler, status, responseHeaders)
                || exitAfterHandling401(channel, future, response, request, statusCode, realm, proxyServer) || //
                exitAfterHandling407(channel, future, response, request, statusCode, realm, proxyServer) || //
View Full Code Here

TOP

Related Classes of org.asynchttpclient.Realm$RealmBuilder

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.