Java源码示例:org.asynchttpclient.Realm
示例1
private Zendesk(AsyncHttpClient client, String url, String username, String password, Map<String, String> headers) {
this.logger = LoggerFactory.getLogger(Zendesk.class);
this.closeClient = client == null;
this.oauthToken = null;
this.client = client == null ? new DefaultAsyncHttpClient() : client;
this.url = url.endsWith("/") ? url + "api/v2" : url + "/api/v2";
if (username != null) {
this.realm = new Realm.Builder(username, password)
.setScheme(Realm.AuthScheme.BASIC)
.setUsePreemptiveAuth(true)
.build();
} else {
if (password != null) {
throw new IllegalStateException("Cannot specify token or password without specifying username");
}
this.realm = null;
}
this.headers = Collections.unmodifiableMap(headers);
this.mapper = createMapper();
}
示例2
public ClickHouseClient(String endpoint, String username, String password) {
this.endpoint = endpoint;
this.optParams = new ArrayList<>();
AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder()
.setRealm(new Realm.Builder(username, password)
.setUsePreemptiveAuth(true)
.setScheme(Realm.AuthScheme.BASIC)
.build())
.build();
this.httpClient = new DefaultAsyncHttpClient(config);
}
示例3
private void kerberosChallenge(Realm realm,
Request request,
HttpHeaders headers) throws SpnegoEngineException {
Uri uri = request.getUri();
String host = withDefault(request.getVirtualHost(), uri.getHost());
String challengeHeader = SpnegoEngine.instance(realm.getPrincipal(),
realm.getPassword(),
realm.getServicePrincipalName(),
realm.getRealmName(),
realm.isUseCanonicalHostname(),
realm.getCustomLoginConfig(),
realm.getLoginContextName()).generateToken(host);
headers.set(AUTHORIZATION, NEGOTIATE + " " + challengeHeader);
}