org.apache.http.auth.AuthState#getAuthScheme ( )源码实例Demo

下面列出了org.apache.http.auth.AuthState#getAuthScheme ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jenkins-client-java   文件: PreemptiveAuth.java
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    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");
            }
            authState.update(authScheme, creds);
        }
    }
}
 
源代码2 项目: attic-polygene-java   文件: WebRealmServiceTest.java
@Override
public void process( final HttpRequest request, final HttpContext context )
    throws HttpException, IOException
{
    AuthState authState = (AuthState) context.getAttribute( ClientContext.TARGET_AUTH_STATE );
    CredentialsProvider credsProvider = (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 creds = credsProvider.getCredentials( authScope );
        // If found, generate BasicScheme preemptively
        if( creds != null )
        {
            authState.setAuthScheme( new BasicScheme() );
            authState.setCredentials( creds );
        }
    }
}
 
源代码3 项目: hawkular-agent   文件: JolokiaClientFactory.java
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);

    if (authState.getAuthScheme() == null) {
        CredentialsProvider credsProvider = (CredentialsProvider) context
                .getAttribute(HttpClientContext.CREDS_PROVIDER);
        HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST);
        Credentials creds = credsProvider
                .getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
        if (creds == null) {
            throw new HttpException("No credentials given for preemptive authentication");
        }
        authState.update(authScheme, creds);
    }
}
 
源代码4 项目: activemq-artemis   文件: UriStrategy.java
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
   AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);

   // If no auth scheme available yet, try to initialize it preemptively
   if (authState.getAuthScheme() == null) {
      AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
      CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
      HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.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");
         }
         authState.update(authScheme, creds);
      }
   }
}
 
源代码5 项目: verigreen   文件: PreemptiveAuth.java
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    Credentials creds;
    
    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) {
            creds =
                    credsProvider.getCredentials(new AuthScope(
                            targetHost.getHostName(),
                            targetHost.getPort()));
            if (creds == null) {
                throw new HttpException("No credentials for preemptive authentication");
            }
            authState.update(authScheme, creds);
        }
    }
}
 
@Override
public void process(final HttpRequest request, final HttpContext context) {
    // never ever send credentials preemptively to a host which is not the configured Gerrit host
    if (!isForGerritHost(request)) {
        return;
    }

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

    // if no auth scheme available yet, try to initialize it preemptively
    if (authState.getAuthScheme() == null) {
        AuthScheme authScheme = (AuthScheme) context.getAttribute(PREEMPTIVE_AUTH);
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(authData.getLogin(), authData.getPassword());
        authState.update(authScheme, creds);
    }
}
 
源代码7 项目: YiBo   文件: LibRequestDirector.java
private void processChallenges(
        final Map<String, Header> challenges,
        final AuthState authState,
        final AuthenticationHandler authHandler,
        final HttpResponse response,
        final HttpContext context)
            throws MalformedChallengeException, AuthenticationException {

    AuthScheme authScheme = authState.getAuthScheme();
    if (authScheme == null) {
        // Authentication not attempted before
        authScheme = authHandler.selectScheme(challenges, response, context);
        authState.setAuthScheme(authScheme);
    }
    String id = authScheme.getSchemeName();

    Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
    if (challenge == null) {
        throw new AuthenticationException(id +
            " authorization challenge expected, but not found");
    }
    authScheme.processChallenge(challenge);
    if (DEBUG) {
    	Logger.debug("Authorization challenge processed");
    }
}
 
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    //
    // get the authentication state for the request
    //
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    //
    // if no auth scheme avaialble yet, try to initialize it preemptively
    //
    if (authState.getAuthScheme() == null) {
        // check if credentials are set
        if (this.credentials == null) {
            throw new HttpException("No credentials for preemptive authentication");
        }

        // add the credentials to the auth state
        authState.setAuthScheme(this.basicAuthScheme);
        authState.setCredentials(this.credentials);

        // HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        //CredentialsProvider credsProvider = (CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
    }
}
 
源代码9 项目: cloudhopper-commons   文件: HttpSender.java
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    
    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(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
            if (creds == null) {
                throw new HttpException("No credentials for preemptive authentication");
            }
            authState.setAuthScheme(authScheme);
            authState.setCredentials(creds);
        }
    }
    
}
 
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
源代码11 项目: lucene-solr   文件: PreemptiveAuth.java
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException,
    IOException {

  AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
  // If no auth scheme available yet, try to initialize it preemptively
  if (authState.getAuthScheme() == null) {
    CredentialsProvider credsProvider = (CredentialsProvider) context
        .getAttribute(ClientContext.CREDS_PROVIDER);
    Credentials creds = credsProvider.getCredentials(AuthScope.ANY);
    authState.update(authScheme, creds);
  }
}
 
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
  HttpClientContext clientContext = HttpClientContext.adapt(context);
  AuthState authState = clientContext.getTargetAuthState();
  if (authState.getAuthScheme() == null) {
    CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    HttpHost targetHost = clientContext.getTargetHost();
    Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
    if (creds != null) {
      authState.update(new BasicScheme(), creds);
    }
  }
}
 
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
public void process(HttpRequest httprequest, HttpContext httpcontext)
{
    AuthState authstate = (AuthState)httpcontext.getAttribute("http.auth.target-scope");
    CredentialsProvider credentialsprovider = (CredentialsProvider)httpcontext.getAttribute("http.auth.credentials-provider");
    HttpHost httphost = (HttpHost)httpcontext.getAttribute("http.target_host");
    if (authstate.getAuthScheme() == null)
    {
        org.apache.http.auth.Credentials credentials = credentialsprovider.getCredentials(new AuthScope(httphost.getHostName(), httphost.getPort()));
        if (credentials != null)
        {
            authstate.setAuthScheme(new BasicScheme());
            authstate.setCredentials(credentials);
        }
    }
}
 
源代码18 项目: MiBandDecompiled   文件: c.java
public void process(HttpRequest httprequest, HttpContext httpcontext)
{
    AuthState authstate = (AuthState)httpcontext.getAttribute("http.auth.target-scope");
    CredentialsProvider credentialsprovider = (CredentialsProvider)httpcontext.getAttribute("http.auth.credentials-provider");
    HttpHost httphost = (HttpHost)httpcontext.getAttribute("http.target_host");
    if (authstate.getAuthScheme() == null)
    {
        org.apache.http.auth.Credentials credentials = credentialsprovider.getCredentials(new AuthScope(httphost.getHostName(), httphost.getPort()));
        if (credentials != null)
        {
            authstate.setAuthScheme(new BasicScheme());
            authstate.setCredentials(credentials);
        }
    }
}
 
源代码19 项目: ghwatch   文件: RemoteSystemClient.java
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
  AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
  CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
  HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

  if (authState.getAuthScheme() == null) {
    AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
    Credentials creds = credsProvider.getCredentials(authScope);
    if (creds != null) {
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(creds);
    }
  }
}
 
源代码20 项目: cloudhopper-commons   文件: HttpPostMain.java
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    
    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(
                    new AuthScope(
                            targetHost.getHostName(), 
                            targetHost.getPort()));
            if (creds == null) {
                throw new HttpException("No credentials for preemptive authentication");
            }
            authState.setAuthScheme(authScheme);
            authState.setCredentials(creds);
        }
    }
    
}