本文整理汇总了Java中com.squareup.okhttp.Credentials类的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credentials类属于com.squareup.okhttp包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
public Request authenticate(Proxy proxy, Response response) throws IOException {
List<Challenge> challenges = response.challenges();
Request request = response.request();
HttpUrl url = request.httpUrl();
int size = challenges.size();
for (int i = 0; i < size; i++) {
Challenge challenge = (Challenge) challenges.get(i);
if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
PasswordAuthentication auth = java.net.Authenticator
.requestPasswordAuthentication(url.host(), getConnectToInetAddress(proxy,
url), url.port(), url.scheme(), challenge.getRealm(), challenge
.getScheme(), url.url(), RequestorType.SERVER);
if (auth != null) {
return request.newBuilder().header("Authorization", Credentials.basic(auth
.getUserName(), new String(auth.getPassword()))).build();
}
}
}
return null;
}
示例2: authenticate
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
public final Request authenticate(Proxy paramProxy, Response paramResponse)
throws IOException
{
List localList = paramResponse.challenges();
Request localRequest = paramResponse.request;
URL localURL = localRequest.url();
int i = 0;
int j = localList.size();
while (i < j)
{
Challenge localChallenge = (Challenge)localList.get(i);
if ("Basic".equalsIgnoreCase(localChallenge.scheme))
{
PasswordAuthentication localPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(localURL.getHost(), getConnectToInetAddress(paramProxy, localURL), localURL.getPort(), localURL.getProtocol(), localChallenge.realm, localChallenge.scheme, localURL, Authenticator.RequestorType.SERVER);
if (localPasswordAuthentication != null)
{
String str = Credentials.basic(localPasswordAuthentication.getUserName(), new String(localPasswordAuthentication.getPassword()));
return localRequest.newBuilder().header("Authorization", str).build();
}
}
i++;
}
return null;
}
示例3: authenticateProxy
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
public final Request authenticateProxy(Proxy paramProxy, Response paramResponse)
throws IOException
{
List localList = paramResponse.challenges();
Request localRequest = paramResponse.request;
URL localURL = localRequest.url();
int i = 0;
int j = localList.size();
while (i < j)
{
Challenge localChallenge = (Challenge)localList.get(i);
if ("Basic".equalsIgnoreCase(localChallenge.scheme))
{
InetSocketAddress localInetSocketAddress = (InetSocketAddress)paramProxy.address();
PasswordAuthentication localPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(localInetSocketAddress.getHostName(), getConnectToInetAddress(paramProxy, localURL), localInetSocketAddress.getPort(), localURL.getProtocol(), localChallenge.realm, localChallenge.scheme, localURL, Authenticator.RequestorType.PROXY);
if (localPasswordAuthentication != null)
{
String str = Credentials.basic(localPasswordAuthentication.getUserName(), new String(localPasswordAuthentication.getPassword()));
return localRequest.newBuilder().header("Proxy-Authorization", str).build();
}
}
i++;
}
return null;
}
示例4: getRequestInterceptor
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
@NonNull
private RequestInterceptor getRequestInterceptor() {
return new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
User user = UserInfoMgr.getInstance().getUser();
if (user != null) {
String basic = Credentials.basic(user.getUsername(), user.getPassword());
request.addHeader("Authorization", basic);
request.addHeader("UserName", user.getUsername());
request.addHeader("FacilityName", user.getFacilityName());
}
addDeviceInfoToRequestHeader(request);
}
};
}
示例5: authenticate
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
@Override public Request authenticate(Proxy proxy, Response response) throws IOException {
List<Challenge> challenges = response.challenges();
Request request = response.request();
URL url = request.url();
for (int i = 0, size = challenges.size(); i < size; i++) {
Challenge challenge = challenges.get(i);
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue;
PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication(
url.getHost(), getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
challenge.getRealm(), challenge.getScheme(), url, RequestorType.SERVER);
if (auth == null) continue;
String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword()));
return request.newBuilder()
.header("Authorization", credential)
.build();
}
return null;
}
示例6: authenticateProxy
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
@Override public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
List<Challenge> challenges = response.challenges();
Request request = response.request();
URL url = request.url();
for (int i = 0, size = challenges.size(); i < size; i++) {
Challenge challenge = challenges.get(i);
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue;
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication(
proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
RequestorType.PROXY);
if (auth == null) continue;
String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword()));
return request.newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
return null;
}
示例7: createHttpProxyRequest
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
private Request createHttpProxyRequest(InetSocketAddress address, String proxyUsername,
String proxyPassword) {
HttpUrl tunnelUrl = new HttpUrl.Builder()
.scheme("https")
.host(address.getHostName())
.port(address.getPort())
.build();
Request.Builder request = new Request.Builder()
.url(tunnelUrl)
.header("Host", tunnelUrl.host() + ":" + tunnelUrl.port())
.header("User-Agent", userAgent);
// If we have proxy credentials, set them right away
if (proxyUsername != null && proxyPassword != null) {
request.header("Proxy-Authorization", Credentials.basic(proxyUsername, proxyPassword));
}
return request.build();
}
示例8: applyToParams
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (username == null && password == null) {
return;
}
headerParams.put("Authorization", Credentials.basic(
username == null ? "" : username,
password == null ? "" : password));
}
示例9: authenticateProxy
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
List<Challenge> challenges = response.challenges();
Request request = response.request();
HttpUrl url = request.httpUrl();
int size = challenges.size();
for (int i = 0; i < size; i++) {
Challenge challenge = (Challenge) challenges.get(i);
if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
PasswordAuthentication auth = java.net.Authenticator
.requestPasswordAuthentication(proxyAddress.getHostName(),
getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url
.scheme(), challenge.getRealm(), challenge.getScheme(),
url.url(), RequestorType.PROXY);
if (auth != null) {
return request.newBuilder().header("Proxy-Authorization", Credentials.basic
(auth.getUserName(), new String(auth.getPassword()))).build();
}
}
}
return null;
}
示例10: doInBackground
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
/**
*
* @param params
* @return
*/
@Override
protected String doInBackground(Void... params) {
OkHttpClient client = new OkHttpClient();
String cred = Credentials.basic(_key, _secret);
FormEncodingBuilder formBody = new FormEncodingBuilder();
formBody.add("grant_type", "client_credentials");
Request request = new Request.Builder()
.url(TWITTER_AUTH_URL)
.post(formBody.build())
.addHeader("Authorization", cred)
.addHeader("ContentType", "application/x-www-form-urlencoded;charset=UTF-8")
.addHeader("Accept-Encoding", "gzip")
.build();
try {
Response response = client.newCall(request).execute();
if (isZipped(response)) {
return unzip(response.body());
} else {
return response.body().string();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例11: sendGcmTokenToServer
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
public GcmRegistrationStatus sendGcmTokenToServer() throws Exception {
if (mJenkinsUserEntity == null) {
return null;
}
// Retrieve crumbInfo
CrumbInfoEntity crumbInfoEntity = retrieveCrumbInfo();
if (crumbInfoEntity != null && crumbInfoEntity.isCsrfEnabled()) {
setHeader(crumbInfoEntity.getCrumbRequestField(), crumbInfoEntity.getCrumb());
}
FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
formEncodingBuilder.add("token", mJenkinsUserEntity.getSenderId());
String credential = Credentials
.basic(mJenkinsUserEntity.getUsername(), mJenkinsUserEntity.getToken());
setHeader("Authorization", credential);
setRequestBody(formEncodingBuilder.build());
// Send to gcm/regsiter
super.url = String.format("%sgcm/register", mJenkinsUserEntity.getUrl());
setMethod(HttpMethod.POST);
execute();
final int statusCode = getResponse().code();
GcmRegistrationStatus status = new GcmRegistrationStatus();
status.setStatusCode(statusCode);
if (statusCode != 200) {
log("Sending registering token failed with satus code %s", statusCode);
status.setStatus(false);
} else {
status.setStatus(true);
}
return status;
}
示例12: readArtifactVersions
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
@Override
public List<String> readArtifactVersions(Service service, Module module, boolean includeSnapshots) {
List<String> versions = new LinkedList<>();
if (service.getMavenGroupId() != null
&& !service.getMavenGroupId().isEmpty()
&& module.getMavenArtifactId() != null
&& !module.getMavenArtifactId().isEmpty()) {
try {
Request.Builder builder = new Request.Builder();
String mavenRepo = parameters.getString(Const.MAVEN_URL, Const.MAVEN_URL_DEFAULT);
String baseUrl = mavenRepo
+ service.getMavenGroupId().replace(".", "/")
+ "/"
+ module.getMavenArtifactId()
+ "/";
String url = baseUrl + "maven-metadata.xml";
builder.url(url);
String mavenUsername = parameters.getString(Const.MAVEN_USERNAME, Const.MAVEN_USERNAME_DEFAULT);
String mavenPassword = parameters.getString(Const.MAVEN_PASSWORD, Const.MAVEN_PASSWORD_DEFAULT);
if (!mavenUsername.equals(Const.MAVEN_USERNAME_DEFAULT)) {
String credential = Credentials.basic(mavenUsername, mavenPassword);
builder.header("Authorization", credential);
}
Request request = builder.build();
Response response = client.newCall(request).execute();
try (InputStream inputStream = response.body().byteStream()) {
versions = processMavenStream(inputStream, baseUrl, includeSnapshots);
}
} catch (Exception ex) {
LOGGER.error("Error reading maven version from {} {}, {}",
service.getMavenGroupId(),
module.getMavenArtifactId(),
ex.getMessage());
}
}
return versions;
}
示例13: determineSnapshotVersion
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
private String determineSnapshotVersion(String baseUrl, String snapshot) {
try {
Request.Builder builder = new Request.Builder();
String url = baseUrl
+ snapshot
+ "/maven-metadata.xml";
builder.url(url);
String mavenUsername = parameters.getString(Const.MAVEN_USERNAME, Const.MAVEN_USERNAME_DEFAULT);
String mavenPassword = parameters.getString(Const.MAVEN_PASSWORD, Const.MAVEN_PASSWORD_DEFAULT);
if (!mavenUsername.equals(Const.MAVEN_USERNAME_DEFAULT)) {
String credential = Credentials.basic(mavenUsername, mavenPassword);
builder.header("Authorization", credential);
}
Request request = builder.build();
Response response = client.newCall(request).execute();
try (InputStream inputStream = response.body().byteStream()) {
return snapshot + "-" + processMavenSnapshotStream(inputStream);
}
} catch (Exception ex) {
LOGGER.error("Error reading maven snapshot version data from {} {}, {}",
baseUrl,
snapshot,
ex.getMessage());
}
return null;
}
示例14: BasicAuthenticator
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
BasicAuthenticator(){
credentials = Credentials.basic(user, password);
}
示例15: getHardcodedApiCredentials
import com.squareup.okhttp.Credentials; //导入依赖的package包/类
public static String getHardcodedApiCredentials() throws ConfigJsonIOException {
return
Credentials.basic(getHardcodedApiUser(),
getHardcodedApiPass());
}