Java 类com.squareup.okhttp.Credentials 实例源码

项目:boohee_v5.6    文件:AuthenticatorAdapter.java   
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;
}
项目:boohee_v5.6    文件:AuthenticatorAdapter.java   
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;
}
项目:FMTech    文件:AuthenticatorAdapter.java   
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;
}
项目:FMTech    文件:AuthenticatorAdapter.java   
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;
}
项目:lmis-moz-mobile    文件:LMISRestManager.java   
@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);
        }
    };
}
项目:spdymcsclient    文件:AuthenticatorAdapter.java   
@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;

}
项目:spdymcsclient    文件:AuthenticatorAdapter.java   
@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;
}
项目:grpc-java    文件:OkHttpClientTransport.java   
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();
}
项目:afp-api-client    文件:HttpBasicAuth.java   
@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));
}
项目:coner-core-client-java    文件:HttpBasicAuth.java   
@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));
}
项目:nifi-swagger-client    文件:HttpBasicAuth.java   
@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));
}
项目:xwallet    文件:TwitterAuthApi.java   
/**
 *
 * @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;
}
项目:swaggy-jenkins    文件:HttpBasicAuth.java   
@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));
}
项目:tradeshift-platform-sdk    文件:HttpBasicAuth.java   
@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));
}
项目:nifi-api-client-java    文件:HttpBasicAuth.java   
@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));
}
项目:artikcloud-java    文件:HttpBasicAuth.java   
@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));
}
项目:swagger-aem    文件:HttpBasicAuth.java   
@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));
}
项目:codelibrary-java    文件:HttpBasicAuth.java   
@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));
}
项目:crowdemotion-api-client-java    文件:HttpBasicAuth.java   
@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));
}
项目:ariADDna    文件:HttpBasicAuth.java   
@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));
}
项目:triglav-client-java    文件:HttpBasicAuth.java   
@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));
}
项目:triglav-client-java    文件:HttpBasicAuth.java   
@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));
}
项目:LIO-SDK-API-Integracao-Remota-v1-Java    文件:HttpBasicAuth.java   
@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));
}
项目:tradeshift-app-samples    文件:HttpBasicAuth.java   
@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));
}
项目:openVulnAPI    文件:HttpBasicAuth.java   
@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));
}
项目:birudo    文件:JenkinsClient.java   
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;
}
项目:Hadrian    文件:MavenHelper.java   
@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;
}
项目:Hadrian    文件:MavenHelper.java   
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;
}
项目:EDSApp    文件:NetworkUtils.java   
BasicAuthenticator(){
    credentials = Credentials.basic(user, password);
}
项目:malariapp    文件:NetworkUtils.java   
BasicAuthenticator(){
    credentials = Credentials.basic(user, password);
}
项目:pictureapp    文件:AuthenticationApi.java   
public static String getHardcodedApiCredentials() throws ConfigJsonIOException {
    return
            Credentials.basic(getHardcodedApiUser(),
                    getHardcodedApiPass());
}
项目:pictureapp    文件:AuthenticationApi.java   
public static String getApiCredentialsFromLogin() {
    return
            Credentials.basic(Session.getCredentials().getUsername(),
                    Session.getCredentials().getPassword());
}
项目:octodroid    文件:ApiClient.java   
public void authorization(String username, String password) {
    this.authorization = Credentials.basic(username, password);
}
项目:api-java-client    文件:BasicAuthentication.java   
public static BasicAuthentication basic(final String username, final String password)
{
    return new BasicAuthentication(Credentials.basic(
        checkNotNull(username, "username cannot be null"),
        checkNotNull(password, "password cannot be null")));
}
项目:Hadrian    文件:SmokeTestHelper.java   
public SmokeTestData ExecuteSmokeTest(String smokeTestUrl, String endPoint, String serviceName, String reason) {
    if (smokeTestUrl == null || smokeTestUrl.isEmpty() || endPoint == null || endPoint.isEmpty()) {
        return null;
    }

    LOGGER.info("Smoke testing EP {} with {}", endPoint, smokeTestUrl);

    String url = Const.HTTP + smokeTestUrl.replace(Const.END_POINT, endPoint);
    Timer timer = metricRegistry.timer(
                "smokeTest.duration",
                "serviceName", serviceName,
                "reason", reason);
    try {
        Request.Builder builder = new Request.Builder().url(url);
        if (parameters.getUsername() != null
                && parameters.getUsername().isEmpty()
                && parameters.getPassword() != null
                && parameters.getPassword().isEmpty()) {
            builder.addHeader(
                    "Authorization",
                    Credentials.basic(parameters.getUsername(), parameters.getPassword()));
        }
        Request request = builder.build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()) {
            timer.addTag("result", "success");
            try (InputStream stream = response.body().byteStream()) {
                Reader reader = new InputStreamReader(stream);
                return gson.fromJson(reader, SmokeTestData.class);
            }
        } else {
            timer.addTag("result", "fail");
            LOGGER.warn("Call to {} failed with code {}", url, response.code());
            return null;
        }
    } catch (Exception ex) {
        timer.addTag("result", "fail");
        LOGGER.warn("Call to {} failed with exception {}", url, ex.getMessage());
        return null;
    } finally {
        timer.stop();
    }
}
项目:Hadrian    文件:ServiceBuildHelper.java   
public void triggerBuild(Team team, Service service, String branch, User user) {
    if (team == null 
            || service == null
            || branch == null
            || branch.isEmpty()) {
        return;
    }

    String url = parameters.getString(Const.SERVICE_BUILD_URL, null);
    if (url == null || url.isEmpty()) {
        return;
    }

    String username = parameters.getString(Const.SERVICE_BUILD_USERNAME, null);
    String password = parameters.getString(Const.SERVICE_BUILD_PASSWORD, null);

    ServiceBuildData serviceBuildData = new ServiceBuildData();
    serviceBuildData.group = team.getGitGroup();
    serviceBuildData.project = service.getGitProject();
    serviceBuildData.branch = branch;

    Request.Builder builder = new Request.Builder()
            .url(url);

    if (username != null
            && !username.isEmpty()
            && password != null
            && !password.isEmpty()) {
        builder = builder.addHeader("Authorization", Credentials.basic(username, password));
    }

    RequestBody body = RequestBody.create(Const.JSON_MEDIA_TYPE, gson.toJson(serviceBuildData));

    Request httpRequest = builder.post(body).build();

    try {
        Response resp = client.newCall(httpRequest).execute();

        if (resp.isSuccessful()) {
            LOGGER.warn("Build triggered to {} with code {}", url, resp.code());

            Map<String, String> notes = new HashMap<>();
            notes.put("Reason", "Manually requested build");
            notes.put("Source Branch",branch);

            Audit audit = new Audit();
            audit.serviceId = service.getServiceId();
            audit.setTimePerformed(GMT.getGmtAsDate());
            audit.timeRequested = GMT.getGmtAsDate();
            audit.requestor = user.getUsername();
            audit.type = Type.service;
            audit.operation = Operation.build;
            audit.successfull = true;
            audit.notes = gson.toJson(notes);

            dataAccess.saveAudit(audit, null);
        } else {
            LOGGER.warn("Build not triggered {}, code {}", url, resp.code());
        }
    } catch (Exception ex) {
        LOGGER.warn("Error while triggering build {}, error {}", url, ex.getMessage());
    }
}
项目:chailmis-android    文件:AuthInterceptor.java   
private String encodeCredentialsForBasicAuthorization() {
    return Credentials.basic(user.getUsername(), user.getPassword());

}