当前位置: 首页>>代码示例>>Java>>正文


Java AuthScheme.getRealm方法代码示例

本文整理汇总了Java中org.apache.http.auth.AuthScheme.getRealm方法的典型用法代码示例。如果您正苦于以下问题:Java AuthScheme.getRealm方法的具体用法?Java AuthScheme.getRealm怎么用?Java AuthScheme.getRealm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.auth.AuthScheme的用法示例。


在下文中一共展示了AuthScheme.getRealm方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
/**
 * If no auth scheme has been selected for the given context, consider each
 * of the preferred auth schemes and select the first one for which an
 * AuthScheme and matching Credentials are available.
 */
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    if (authState != null && authState.getAuthScheme() != null) {
        return;
    }
    HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    CredentialsProvider creds = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
    AuthSchemeRegistry schemes = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
    for (Object schemeName : (Iterable) context.getAttribute(ClientContext.AUTH_SCHEME_PREF)) {
        AuthScheme scheme = schemes.getAuthScheme(schemeName.toString(), request.getParams());
        if (scheme != null) {
            AuthScope targetScope = new AuthScope(target.getHostName(), target.getPort(), scheme.getRealm(), scheme
                    .getSchemeName());
            Credentials cred = creds.getCredentials(targetScope);
            if (cred != null) {
                authState.setAuthScheme(scheme);
                authState.setCredentials(cred);
                return;
            }
        }
    }
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:28,代码来源:PreemptiveAuthorizer.java

示例2: select

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Auth scheme registry not set in the context");
        }
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Credentials provider not set in the context");
        }
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (Log.isLoggable(TAG, Log.WARN)) {
                    Log.w(TAG, "Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:69,代码来源:AuthenticationStrategyImpl.java

示例3: select

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
@Override
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        this.log.debug("Auth scheme registry not set in the context");
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ROOT));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:66,代码来源:AuthenticationStrategyImpl.java

示例4: process

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
/**
 * If no auth scheme has been selected for the given context, consider each
 * of the preferred auth schemes and select the first one for which an
 * AuthScheme and matching Credentials are available.
 */
@SuppressWarnings("rawtypes")
public void process(HttpRequest request, HttpContext context)
		throws HttpException, IOException {
	AuthState authState = (AuthState) context
			.getAttribute(ClientContext.TARGET_AUTH_STATE);
	if (authState != null && authState.getAuthScheme() != null) {
		return;
	}
	HttpHost target = (HttpHost) context
			.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
	CredentialsProvider creds = (CredentialsProvider) context
			.getAttribute(ClientContext.CREDS_PROVIDER);
	AuthSchemeRegistry schemes = (AuthSchemeRegistry) context
			.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
	for (Object schemeName : (Iterable) context
			.getAttribute(ClientContext.AUTH_SCHEME_PREF)) {
		AuthScheme scheme = schemes.getAuthScheme(schemeName.toString(),
				request.getParams());
		if (scheme != null) {
			AuthScope targetScope = new AuthScope(target.getHostName(),
					target.getPort(), scheme.getRealm(),
					scheme.getSchemeName());
			Credentials cred = creds.getCredentials(targetScope);
			if (cred != null) {
				authState.setAuthScheme(scheme);
				authState.setCredentials(cred);
				return;
			}
		}
	}
}
 
开发者ID:Simbacode,项目名称:mobipayments,代码行数:37,代码来源:PreemptiveAuthorizer.java

示例5: select

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    if (challenges == null) {
        throw new IllegalArgumentException("Map of auth challenges may not be null");
    }
    if (authhost == null) {
        throw new IllegalArgumentException("Host may not be null");
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }

    Queue<AuthOption> options = new LinkedList<AuthOption>();
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }

    AuthScheme authScheme;
    try {
        authScheme = this.handler.selectScheme(challenges, response, context);
    } catch (AuthenticationException ex) {
        if (this.log.isWarnEnabled()) {
            this.log.warn(ex.getMessage(), ex);
        }
        return options;
    }
    String id = authScheme.getSchemeName();
    Header challenge = challenges.get(id.toLowerCase(Locale.US));
    authScheme.processChallenge(challenge);

    AuthScope authScope = new AuthScope(
            authhost.getHostName(),
            authhost.getPort(),
            authScheme.getRealm(),
            authScheme.getSchemeName());

    Credentials credentials = credsProvider.getCredentials(authScope);
    if (credentials != null) {
        options.add(new AuthOption(authScheme, credentials));
    }
    return options;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:AuthenticationStrategyAdaptor.java

示例6: select

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    if (challenges == null) {
        throw new IllegalArgumentException("Map of auth challenges may not be null");
    }
    if (authhost == null) {
        throw new IllegalArgumentException("Host may not be null");
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }

    Queue<AuthOption> options = new LinkedList<AuthOption>();
    AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
            ClientContext.AUTHSCHEME_REGISTRY);
    if (registry == null) {
        this.log.debug("Auth scheme registry not set in the context");
        return options;
    }
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }

    @SuppressWarnings("unchecked")
    List<String> authPrefs = (List<String>) response.getParams().getParameter(this.prefParamName);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for (String id: authPrefs) {
        Header challenge = challenges.get(id.toLowerCase(Locale.US));
        if (challenge != null) {
            try {
                AuthScheme authScheme = registry.getAuthScheme(id, response.getParams());
                authScheme.processChallenge(challenge);

                AuthScope authScope = new AuthScope(
                        authhost.getHostName(),
                        authhost.getPort(),
                        authScheme.getRealm(),
                        authScheme.getSchemeName());

                Credentials credentials = credsProvider.getCredentials(authScope);
                if (credentials != null) {
                    options.add(new AuthOption(authScheme, credentials));
                }
            } catch (IllegalStateException e) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:74,代码来源:AuthenticationStrategyImpl.java

示例7: select

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
@Override
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }

    final AuthScheme authScheme;
    try {
        authScheme = this.handler.selectScheme(challenges, response, context);
    } catch (final AuthenticationException ex) {
        if (this.log.isWarnEnabled()) {
            this.log.warn(ex.getMessage(), ex);
        }
        return options;
    }
    final String id = authScheme.getSchemeName();
    final Header challenge = challenges.get(id.toLowerCase(Locale.ROOT));
    authScheme.processChallenge(challenge);

    final AuthScope authScope = new AuthScope(
            authhost.getHostName(),
            authhost.getPort(),
            authScheme.getRealm(),
            authScheme.getSchemeName());

    final Credentials credentials = credsProvider.getCredentials(authScope);
    if (credentials != null) {
        options.add(new AuthOption(authScheme, credentials));
    }
    return options;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:45,代码来源:AuthenticationStrategyAdaptor.java

示例8: updateAuthState

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
private void updateAuthState(
    final AuthState authState,
    final HttpHost host,
    final CredentialsProvider credsProvider) {

  if (!authState.isValid()) {
    return;
  }

  String hostname = host.getHostName();
  int port = host.getPort();
  if (port < 0) {
    Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
    port = scheme.getDefaultPort();
  }

  AuthScheme authScheme = authState.getAuthScheme();
  AuthScope authScope = new AuthScope(
      hostname,
      port,
      authScheme.getRealm(),
      authScheme.getSchemeName());

  if (this.log.isDebugEnabled()) {
    this.log.debug("Authentication scope: " + authScope);
  }
  Credentials creds = authState.getCredentials();
  if (creds == null) {
    creds = credsProvider.getCredentials(authScope);
    if (this.log.isDebugEnabled()) {
      if (creds != null) {
        this.log.debug("Found credentials");
      } else {
        this.log.debug("Credentials not found");
      }
    }
  } else {
    if (authScheme.isComplete()) {
      this.log.debug("Authentication failed");
      creds = null;
    }
  }
  authState.setAuthScope(authScope);
  authState.setCredentials(creds);
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:46,代码来源:DefaultRequestDirector.java

示例9: updateAuthState

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
private void updateAuthState(
        final AuthState authState, 
        final HttpHost host,
        final CredentialsProvider credsProvider) {
    
    if (!authState.isValid()) {
        return;
    }
    
    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }
    
    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(
            hostname,
            port,
            authScheme.getRealm(), 
            authScheme.getSchemeName());  
    
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication scope: " + authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (this.log.isDebugEnabled()) {
            if (creds != null) {
                this.log.debug("Found credentials");
            } else {
                this.log.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
            this.log.debug("Authentication failed");
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}
 
开发者ID:tdopires,项目名称:cJUnit-mc626,代码行数:46,代码来源:DefaultRequestDirector.java

示例10: updateAuthState

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
private void updateAuthState(
        final AuthState authState,
        final HttpHost host,
        final CredentialsProvider credsProvider) {

    if (!authState.isValid()) {
        return;
    }

    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }

    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(
            hostname,
            port,
            authScheme.getRealm(),
            authScheme.getSchemeName());

    if (DEBUG) {
    	Logger.debug("Authentication scope: {}", authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (DEBUG) {
            if (creds != null) {
            	Logger.debug("Found credentials");
            } else {
            	Logger.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
        	if (DEBUG) {
        		Logger.debug("Authentication failed");
        	}
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}
 
开发者ID:cattong,项目名称:YiBo,代码行数:48,代码来源:LibRequestDirector.java

示例11: updateAuthState

import org.apache.http.auth.AuthScheme; //导入方法依赖的package包/类
private void updateAuthState(
        final AuthState authState,
        final HttpHost host,
        final CredentialsProvider credsProvider) {

    if (!authState.isValid()) {
        return;
    }

    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }

    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(
            hostname,
            port,
            authScheme.getRealm(),
            authScheme.getSchemeName());

    if (Constants.DEBUG) {
    	logger.debug("Authentication scope: {}", authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (Constants.DEBUG) {
            if (creds != null) {
            	logger.debug("Found credentials");
            } else {
            	logger.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
        	if (Constants.DEBUG) {
        		logger.debug("Authentication failed");
        	}
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}
 
开发者ID:yibome,项目名称:yibo-library,代码行数:48,代码来源:YiBoRequestDirector.java


注:本文中的org.apache.http.auth.AuthScheme.getRealm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。